1
1
package graphql .validation .rules ;
2
2
3
+ import graphql .GraphQLContext ;
3
4
import graphql .PublicApi ;
4
5
import graphql .execution .ResultPath ;
5
6
import graphql .language .SourceLocation ;
@@ -55,6 +56,8 @@ public enum ValidatedElement {
55
56
private final Object validatedValue ;
56
57
private final GraphQLInputType validatedType ;
57
58
private final ValidatedElement validatedElement ;
59
+
60
+ private final GraphQLContext graphQLContext ;
58
61
private final List <GraphQLAppliedDirective > directives ;
59
62
60
63
private ValidationEnvironment (Builder builder ) {
@@ -71,6 +74,7 @@ private ValidationEnvironment(Builder builder) {
71
74
this .location = builder .location ;
72
75
this .validatedValue = builder .validatedValue ;
73
76
this .validatedElement = builder .validatedElement ;
77
+ this .graphQLContext = builder .graphQLContext ;
74
78
this .directives = builder .directives ;
75
79
}
76
80
@@ -135,6 +139,10 @@ public List<GraphQLAppliedDirective> getDirectives() {
135
139
return directives ;
136
140
}
137
141
142
+ public GraphQLContext getGraphQLContext () {
143
+ return graphQLContext ;
144
+ }
145
+
138
146
public ValidationEnvironment transform (Consumer <Builder > builderConsumer ) {
139
147
Builder builder = newValidationEnvironment ().validationEnvironment (this );
140
148
builderConsumer .accept (builder );
@@ -156,6 +164,7 @@ public static class Builder {
156
164
private GraphQLInputType validatedType ;
157
165
private ValidatedElement validatedElement ;
158
166
private List <GraphQLAppliedDirective > directives = Collections .emptyList ();
167
+ private GraphQLContext graphQLContext = GraphQLContext .getDefault ();
159
168
160
169
public Builder validationEnvironment (ValidationEnvironment validationEnvironment ) {
161
170
this .argument = validationEnvironment .argument ;
@@ -172,6 +181,7 @@ public Builder validationEnvironment(ValidationEnvironment validationEnvironment
172
181
this .validatedValue = validationEnvironment .validatedValue ;
173
182
this .validatedElement = validationEnvironment .validatedElement ;
174
183
this .directives = validationEnvironment .directives ;
184
+ this .graphQLContext = validationEnvironment .graphQLContext ;
175
185
return this ;
176
186
}
177
187
@@ -184,6 +194,7 @@ public Builder dataFetchingEnvironment(DataFetchingEnvironment dataFetchingEnvir
184
194
location (dataFetchingEnvironment .getField ().getSourceLocation ());
185
195
argumentValues (dataFetchingEnvironment .getArguments ());
186
196
validatedElement (ValidatedElement .FIELD );
197
+ graphQLContext (dataFetchingEnvironment .getGraphQlContext ());
187
198
return this ;
188
199
}
189
200
@@ -252,6 +263,11 @@ public Builder locale(Locale locale) {
252
263
return this ;
253
264
}
254
265
266
+ public Builder graphQLContext (GraphQLContext graphQLContext ) {
267
+ this .graphQLContext = graphQLContext ;
268
+ return this ;
269
+ }
270
+
255
271
public Builder directives (List <GraphQLAppliedDirective > directives ) {
256
272
this .directives = directives ;
257
273
return this ;
0 commit comments