|
1 | 1 | package graphql.execution; |
2 | 2 |
|
3 | 3 | import graphql.PublicApi; |
| 4 | +import graphql.language.SourceLocation; |
4 | 5 | import graphql.schema.DataFetchingEnvironment; |
5 | 6 | import graphql.schema.GraphQLFieldDefinition; |
6 | 7 |
|
|
12 | 13 | @PublicApi |
13 | 14 | public class DataFetcherExceptionHandlerParameters { |
14 | 15 |
|
15 | | - private final ExecutionContext executionContext; |
16 | 16 | private final DataFetchingEnvironment dataFetchingEnvironment; |
17 | | - private final MergedField field; |
18 | | - private final GraphQLFieldDefinition fieldDefinition; |
19 | | - private final Map<String, Object> argumentValues; |
20 | | - private final ExecutionPath path; |
21 | 17 | private final Throwable exception; |
22 | 18 |
|
23 | | - public DataFetcherExceptionHandlerParameters(ExecutionContext executionContext, DataFetchingEnvironment dataFetchingEnvironment, MergedField field, GraphQLFieldDefinition fieldDefinition, Map<String, Object> argumentValues, ExecutionPath path, Throwable exception) { |
24 | | - this.executionContext = executionContext; |
25 | | - this.dataFetchingEnvironment = dataFetchingEnvironment; |
26 | | - this.field = field; |
27 | | - this.fieldDefinition = fieldDefinition; |
28 | | - this.argumentValues = argumentValues; |
29 | | - this.path = path; |
30 | | - this.exception = exception; |
| 19 | + private DataFetcherExceptionHandlerParameters(Builder builder) { |
| 20 | + this.exception = builder.exception; |
| 21 | + this.dataFetchingEnvironment = builder.dataFetchingEnvironment; |
31 | 22 | } |
32 | 23 |
|
33 | | - public static Builder newExceptionParameters() { |
34 | | - return new Builder(); |
| 24 | + public Throwable getException() { |
| 25 | + return exception; |
35 | 26 | } |
36 | 27 |
|
37 | | - public ExecutionContext getExecutionContext() { |
38 | | - return executionContext; |
| 28 | + public ExecutionPath getPath() { |
| 29 | + return dataFetchingEnvironment.getExecutionStepInfo().getPath(); |
39 | 30 | } |
40 | 31 |
|
41 | 32 | public DataFetchingEnvironment getDataFetchingEnvironment() { |
42 | 33 | return dataFetchingEnvironment; |
43 | 34 | } |
44 | 35 |
|
45 | 36 | public MergedField getField() { |
46 | | - return field; |
| 37 | + return dataFetchingEnvironment.getMergedField(); |
47 | 38 | } |
48 | 39 |
|
49 | 40 | public GraphQLFieldDefinition getFieldDefinition() { |
50 | | - return fieldDefinition; |
| 41 | + return dataFetchingEnvironment.getFieldDefinition(); |
51 | 42 | } |
52 | 43 |
|
53 | 44 | public Map<String, Object> getArgumentValues() { |
54 | | - return argumentValues; |
| 45 | + return dataFetchingEnvironment.getArguments(); |
55 | 46 | } |
56 | 47 |
|
57 | | - public ExecutionPath getPath() { |
58 | | - return path; |
| 48 | + public SourceLocation getSourceLocation() { |
| 49 | + return getField().getSingleField().getSourceLocation(); |
59 | 50 | } |
60 | 51 |
|
61 | | - public Throwable getException() { |
62 | | - return exception; |
| 52 | + public static Builder newExceptionParameters() { |
| 53 | + return new Builder(); |
63 | 54 | } |
64 | 55 |
|
65 | 56 | public static class Builder { |
66 | | - ExecutionContext executionContext; |
67 | 57 | DataFetchingEnvironment dataFetchingEnvironment; |
68 | | - MergedField field; |
69 | | - GraphQLFieldDefinition fieldDefinition; |
70 | | - Map<String, Object> argumentValues; |
71 | | - ExecutionPath path; |
72 | 58 | Throwable exception; |
73 | 59 |
|
74 | 60 | private Builder() { |
75 | 61 | } |
76 | 62 |
|
77 | | - public Builder executionContext(ExecutionContext executionContext) { |
78 | | - this.executionContext = executionContext; |
79 | | - return this; |
80 | | - } |
81 | | - |
82 | 63 | public Builder dataFetchingEnvironment(DataFetchingEnvironment dataFetchingEnvironment) { |
83 | 64 | this.dataFetchingEnvironment = dataFetchingEnvironment; |
84 | 65 | return this; |
85 | 66 | } |
86 | 67 |
|
87 | | - public Builder field(MergedField field) { |
88 | | - this.field = field; |
89 | | - return this; |
90 | | - } |
91 | | - |
92 | | - public Builder fieldDefinition(GraphQLFieldDefinition fieldDefinition) { |
93 | | - this.fieldDefinition = fieldDefinition; |
94 | | - return this; |
95 | | - } |
96 | | - |
97 | | - public Builder argumentValues(Map<String, Object> argumentValues) { |
98 | | - this.argumentValues = argumentValues; |
99 | | - return this; |
100 | | - } |
101 | | - |
102 | | - public Builder path(ExecutionPath path) { |
103 | | - this.path = path; |
104 | | - return this; |
105 | | - } |
106 | | - |
107 | 68 | public Builder exception(Throwable exception) { |
108 | 69 | this.exception = exception; |
109 | 70 | return this; |
110 | 71 | } |
111 | 72 |
|
112 | 73 | public DataFetcherExceptionHandlerParameters build() { |
113 | | - return new DataFetcherExceptionHandlerParameters(executionContext, dataFetchingEnvironment, field, fieldDefinition, argumentValues, path, exception); |
| 74 | + return new DataFetcherExceptionHandlerParameters(this); |
114 | 75 | } |
115 | 76 | } |
116 | 77 | } |
0 commit comments