11package graphql .validation .rules ;
22
3+ import graphql .GraphQLContext ;
34import graphql .PublicApi ;
45import graphql .execution .ResultPath ;
56import graphql .language .SourceLocation ;
@@ -55,6 +56,8 @@ public enum ValidatedElement {
5556 private final Object validatedValue ;
5657 private final GraphQLInputType validatedType ;
5758 private final ValidatedElement validatedElement ;
59+
60+ private final GraphQLContext graphQLContext ;
5861 private final List <GraphQLAppliedDirective > directives ;
5962
6063 private ValidationEnvironment (Builder builder ) {
@@ -71,6 +74,7 @@ private ValidationEnvironment(Builder builder) {
7174 this .location = builder .location ;
7275 this .validatedValue = builder .validatedValue ;
7376 this .validatedElement = builder .validatedElement ;
77+ this .graphQLContext = builder .graphQLContext ;
7478 this .directives = builder .directives ;
7579 }
7680
@@ -135,6 +139,10 @@ public List<GraphQLAppliedDirective> getDirectives() {
135139 return directives ;
136140 }
137141
142+ public GraphQLContext getGraphQLContext () {
143+ return graphQLContext ;
144+ }
145+
138146 public ValidationEnvironment transform (Consumer <Builder > builderConsumer ) {
139147 Builder builder = newValidationEnvironment ().validationEnvironment (this );
140148 builderConsumer .accept (builder );
@@ -156,6 +164,7 @@ public static class Builder {
156164 private GraphQLInputType validatedType ;
157165 private ValidatedElement validatedElement ;
158166 private List <GraphQLAppliedDirective > directives = Collections .emptyList ();
167+ private GraphQLContext graphQLContext = GraphQLContext .getDefault ();
159168
160169 public Builder validationEnvironment (ValidationEnvironment validationEnvironment ) {
161170 this .argument = validationEnvironment .argument ;
@@ -172,6 +181,7 @@ public Builder validationEnvironment(ValidationEnvironment validationEnvironment
172181 this .validatedValue = validationEnvironment .validatedValue ;
173182 this .validatedElement = validationEnvironment .validatedElement ;
174183 this .directives = validationEnvironment .directives ;
184+ this .graphQLContext = validationEnvironment .graphQLContext ;
175185 return this ;
176186 }
177187
@@ -184,6 +194,7 @@ public Builder dataFetchingEnvironment(DataFetchingEnvironment dataFetchingEnvir
184194 location (dataFetchingEnvironment .getField ().getSourceLocation ());
185195 argumentValues (dataFetchingEnvironment .getArguments ());
186196 validatedElement (ValidatedElement .FIELD );
197+ graphQLContext (dataFetchingEnvironment .getGraphQlContext ());
187198 return this ;
188199 }
189200
@@ -252,6 +263,11 @@ public Builder locale(Locale locale) {
252263 return this ;
253264 }
254265
266+ public Builder graphQLContext (GraphQLContext graphQLContext ) {
267+ this .graphQLContext = graphQLContext ;
268+ return this ;
269+ }
270+
255271 public Builder directives (List <GraphQLAppliedDirective > directives ) {
256272 this .directives = directives ;
257273 return this ;
0 commit comments