22
22
@ PublicApi
23
23
public class ValidationEnvironment {
24
24
25
+ /**
26
+ * The type of element being validated
27
+ */
28
+ public enum ValidatedElement {
29
+ /**
30
+ * A output field is being validated
31
+ */
32
+ FIELD ,
33
+ /**
34
+ * An argument on a graphql output field is being validated
35
+ */
36
+ ARGUMENT ,
37
+ /**
38
+ * A input type field is being validated
39
+ */
40
+ INPUT_OBJECT_FIELD
41
+ }
42
+
25
43
private final GraphQLFieldsContainer fieldsContainer ;
26
44
private final GraphQLFieldDefinition fieldDefinition ;
27
45
private final GraphQLArgument argument ;
28
- private final GraphQLInputType fieldOrArgumentType ;
29
- private final Object validatedValue ;
30
- private final ExecutionPath fieldOrArgumentPath ;
31
46
private final ExecutionPath executionPath ;
47
+ private final ExecutionPath validatedPath ;
32
48
private final SourceLocation location ;
33
49
private final MessageInterpolator interpolator ;
34
50
private final Map <Class , Object > contextMap ;
35
51
private final Locale locale ;
36
52
private final Map <String , Object > argumentValues ;
53
+ private final Object validatedValue ;
54
+ private final GraphQLInputType validatedType ;
55
+ private final ValidatedElement validatedElement ;
37
56
38
57
private ValidationEnvironment (Builder builder ) {
39
58
this .argument = builder .argument ;
40
59
this .argumentValues = Collections .unmodifiableMap (builder .argumentValues );
41
60
this .contextMap = Collections .unmodifiableMap (builder .contextMap );
42
- this .executionPath = builder .executionPath ;
43
61
this .fieldDefinition = builder .fieldDefinition ;
44
- this .fieldOrArgumentPath = builder .fieldOrArgumentPath ;
45
- this .fieldOrArgumentType = builder .fieldOrArgumentType ;
62
+ this .executionPath = builder .executionPath ;
63
+ this .validatedPath = builder .validatedPath ;
64
+ this .validatedType = builder .validatedType ;
46
65
this .fieldsContainer = builder .fieldsContainer ;
47
66
this .interpolator = builder .interpolator ;
48
67
this .locale = builder .locale ;
49
68
this .location = builder .location ;
50
69
this .validatedValue = builder .validatedValue ;
70
+ this .validatedElement = builder .validatedElement ;
51
71
}
52
72
53
73
public static Builder newValidationEnvironment () {
@@ -71,20 +91,20 @@ public GraphQLArgument getArgument() {
71
91
return argument ;
72
92
}
73
93
74
- public ExecutionPath getExecutionPath () {
75
- return executionPath ;
76
- }
77
-
78
94
public SourceLocation getLocation () {
79
95
return location ;
80
96
}
81
97
82
- public ExecutionPath getFieldOrArgumentPath () {
83
- return fieldOrArgumentPath ;
98
+ public ExecutionPath getValidatedPath () {
99
+ return validatedPath ;
84
100
}
85
101
86
- public GraphQLInputType getFieldOrArgumentType () {
87
- return fieldOrArgumentType ;
102
+ public ExecutionPath getExecutionPath () {
103
+ return executionPath ;
104
+ }
105
+
106
+ public GraphQLInputType getValidatedType () {
107
+ return validatedType ;
88
108
}
89
109
90
110
public Object getValidatedValue () {
@@ -103,6 +123,10 @@ public Locale getLocale() {
103
123
return locale ;
104
124
}
105
125
126
+ public ValidatedElement getValidatedElement () {
127
+ return validatedElement ;
128
+ }
129
+
106
130
public ValidationEnvironment transform (Consumer <Builder > builderConsumer ) {
107
131
Builder builder = newValidationEnvironment ().validationEnvironment (this );
108
132
builderConsumer .accept (builder );
@@ -113,38 +137,47 @@ public static class Builder {
113
137
private final Map <Class , Object > contextMap = new HashMap <>();
114
138
private GraphQLArgument argument ;
115
139
private Map <String , Object > argumentValues = new HashMap <>();
116
- private ExecutionPath executionPath ;
117
140
private GraphQLFieldDefinition fieldDefinition ;
118
- private ExecutionPath fieldOrArgumentPath = ExecutionPath .rootPath ();
119
- private GraphQLInputType fieldOrArgumentType ;
141
+ private ExecutionPath validatedPath = ExecutionPath .rootPath ();
142
+ private ExecutionPath executionPath ;
120
143
private GraphQLFieldsContainer fieldsContainer ;
121
144
private MessageInterpolator interpolator ;
122
145
private Locale locale ;
123
146
private SourceLocation location ;
124
147
private Object validatedValue ;
148
+ private GraphQLInputType validatedType ;
149
+ private ValidatedElement validatedElement ;
125
150
126
151
public Builder validationEnvironment (ValidationEnvironment validationEnvironment ) {
127
152
this .argument = validationEnvironment .argument ;
128
153
this .argumentValues = validationEnvironment .argumentValues ;
129
154
this .contextMap .putAll (validationEnvironment .contextMap );
130
- this .executionPath = validationEnvironment .executionPath ;
131
155
this .fieldDefinition = validationEnvironment .fieldDefinition ;
132
- this .fieldOrArgumentPath = validationEnvironment .fieldOrArgumentPath ;
133
- this .fieldOrArgumentType = validationEnvironment .fieldOrArgumentType ;
156
+ this .executionPath = validationEnvironment .executionPath ;
157
+ this .validatedPath = validationEnvironment .validatedPath ;
158
+ this .validatedType = validationEnvironment .validatedType ;
134
159
this .fieldsContainer = validationEnvironment .fieldsContainer ;
135
160
this .interpolator = validationEnvironment .interpolator ;
136
161
this .locale = validationEnvironment .locale ;
137
162
this .location = validationEnvironment .location ;
138
163
this .validatedValue = validationEnvironment .validatedValue ;
164
+ this .validatedElement = validationEnvironment .validatedElement ;
139
165
return this ;
140
166
}
141
167
142
168
public Builder dataFetchingEnvironment (DataFetchingEnvironment dataFetchingEnvironment ) {
143
169
fieldsContainer (dataFetchingEnvironment .getExecutionStepInfo ().getFieldContainer ());
144
170
fieldDefinition (dataFetchingEnvironment .getFieldDefinition ());
145
171
executionPath (dataFetchingEnvironment .getExecutionStepInfo ().getPath ());
172
+ validatedPath (dataFetchingEnvironment .getExecutionStepInfo ().getPath ());
146
173
location (dataFetchingEnvironment .getField ().getSourceLocation ());
147
174
argumentValues (dataFetchingEnvironment .getArguments ());
175
+ validatedElement (ValidatedElement .FIELD );
176
+ return this ;
177
+ }
178
+
179
+ public Builder argument (GraphQLArgument argument ) {
180
+ this .argument = argument ;
148
181
return this ;
149
182
}
150
183
@@ -158,30 +191,23 @@ public Builder fieldsContainer(GraphQLFieldsContainer fieldsContainer) {
158
191
return this ;
159
192
}
160
193
161
- public Builder fieldDefinition (GraphQLFieldDefinition fieldDefinition ) {
162
- this .fieldDefinition = fieldDefinition ;
163
- return this ;
164
- }
165
-
166
194
public Builder executionPath (ExecutionPath executionPath ) {
167
195
this .executionPath = executionPath ;
168
196
return this ;
169
197
}
170
198
171
- public Builder argument (GraphQLArgument argument ) {
172
- this .argument = argument ;
173
- fieldOrArgumentType (argument .getType ());
174
- fieldOrArgumentPath (ExecutionPath .rootPath ().segment (argument .getName ()));
199
+ public Builder fieldDefinition (GraphQLFieldDefinition fieldDefinition ) {
200
+ this .fieldDefinition = fieldDefinition ;
175
201
return this ;
176
202
}
177
203
178
- public Builder fieldOrArgumentPath ( ExecutionPath fieldOrArgumentPath ) {
179
- this .fieldOrArgumentPath = fieldOrArgumentPath ;
204
+ public Builder validatedElement ( ValidatedElement validatedElement ) {
205
+ this .validatedElement = validatedElement ;
180
206
return this ;
181
207
}
182
208
183
- public Builder fieldOrArgumentType (GraphQLInputType fieldOrArgumentType ) {
184
- this .fieldOrArgumentType = fieldOrArgumentType ;
209
+ public Builder validatedType (GraphQLInputType validatedType ) {
210
+ this .validatedType = validatedType ;
185
211
return this ;
186
212
}
187
213
@@ -190,6 +216,11 @@ public Builder validatedValue(Object validatedValue) {
190
216
return this ;
191
217
}
192
218
219
+ public Builder validatedPath (ExecutionPath validatedPath ) {
220
+ this .validatedPath = validatedPath ;
221
+ return this ;
222
+ }
223
+
193
224
public Builder argumentValues (Map <String , Object > argumentValues ) {
194
225
this .argumentValues = argumentValues ;
195
226
return this ;
0 commit comments