44import com .google .common .collect .HashBiMap ;
55import com .google .common .collect .ImmutableList ;
66import com .google .common .collect .ImmutableMap ;
7+ import graphql .Assert ;
78import graphql .GraphQLContext ;
89import graphql .Internal ;
10+ import graphql .execution .CoercedVariables ;
911import graphql .execution .MergedField ;
12+ import graphql .execution .NormalizedVariables ;
1013import graphql .execution .ValuesResolver ;
1114import graphql .language .Directive ;
1215import graphql .language .Field ;
1316import graphql .normalized .NormalizedInputValue ;
1417import graphql .schema .GraphQLArgument ;
1518import graphql .schema .GraphQLDirective ;
1619import graphql .schema .GraphQLSchema ;
17- import graphql .util .FpKit ;
1820import graphql .util .LockKit ;
1921import org .jetbrains .annotations .Nullable ;
2022
2325import java .util .List ;
2426import java .util .Locale ;
2527import java .util .Map ;
28+ import java .util .function .Supplier ;
2629
30+ import static graphql .Assert .assertNotNull ;
2731import static graphql .collect .ImmutableKit .emptyList ;
2832
2933/**
@@ -37,9 +41,8 @@ public class QueryDirectivesImpl implements QueryDirectives {
3741 private final DirectivesResolver directivesResolver = new DirectivesResolver ();
3842 private final MergedField mergedField ;
3943 private final GraphQLSchema schema ;
40- private final Map <String , Object > coercedVariables ;
41- @ Nullable
42- private final Map <String , NormalizedInputValue > normalizedVariableValues ;
44+ private final CoercedVariables coercedVariables ;
45+ private final Supplier <NormalizedVariables > normalizedVariableValues ;
4346 private final GraphQLContext graphQLContext ;
4447 private final Locale locale ;
4548
@@ -50,13 +53,13 @@ public class QueryDirectivesImpl implements QueryDirectives {
5053 private volatile ImmutableMap <String , List <QueryAppliedDirective >> fieldAppliedDirectivesByName ;
5154 private volatile ImmutableMap <QueryAppliedDirective , Map <String , NormalizedInputValue >> normalizedValuesByAppliedDirective ;
5255
53- public QueryDirectivesImpl (MergedField mergedField , GraphQLSchema schema , Map < String , Object > coercedVariables , Map < String , NormalizedInputValue > normalizedVariableValues , GraphQLContext graphQLContext , Locale locale ) {
54- this .mergedField = mergedField ;
55- this .schema = schema ;
56- this .coercedVariables = coercedVariables ;
57- this .normalizedVariableValues = normalizedVariableValues ;
58- this .graphQLContext = graphQLContext ;
59- this .locale = locale ;
56+ public QueryDirectivesImpl (MergedField mergedField , GraphQLSchema schema , CoercedVariables coercedVariables , Supplier < NormalizedVariables > normalizedVariableValues , GraphQLContext graphQLContext , Locale locale ) {
57+ this .mergedField = assertNotNull ( mergedField ) ;
58+ this .schema = assertNotNull ( schema ) ;
59+ this .coercedVariables = assertNotNull ( coercedVariables ) ;
60+ this .normalizedVariableValues = assertNotNull ( normalizedVariableValues ) ;
61+ this .graphQLContext = assertNotNull ( graphQLContext ) ;
62+ this .locale = assertNotNull ( locale ) ;
6063 }
6164
6265 private void computeValuesLazily () {
@@ -100,14 +103,16 @@ private void computeValuesLazily() {
100103
101104 // create NormalizedInputValue values for directive arguments
102105 Map <QueryAppliedDirective , Map <String , NormalizedInputValue >> normalizedValuesByAppliedDirective = new LinkedHashMap <>();
103- if (this .normalizedVariableValues != null ) {
106+ NormalizedVariables normalizedVariableValues = this .normalizedVariableValues .get ();
107+ if (normalizedVariableValues != null ) {
104108 byNameApplied .values ().forEach (directiveList -> {
105109 for (QueryAppliedDirective queryAppliedDirective : directiveList ) {
106110 GraphQLDirective graphQLDirective = gqlDirectiveCounterPartsInverse .get (queryAppliedDirective );
107111 // we need this counterpart because the ValuesResolver needs the runtime and AST element
108112 Directive directive = directiveCounterParts .get (graphQLDirective );
109113 if (directive != null ) {
110- Map <String , NormalizedInputValue > normalizedArgumentValues = ValuesResolver .getNormalizedArgumentValues (graphQLDirective .getArguments (), directive .getArguments (), this .normalizedVariableValues );
114+ Map <String , NormalizedInputValue > normalizedVariables = normalizedVariableValues .toMap ();
115+ Map <String , NormalizedInputValue > normalizedArgumentValues = ValuesResolver .getNormalizedArgumentValues (graphQLDirective .getArguments (), directive .getArguments (), normalizedVariables );
111116 normalizedValuesByAppliedDirective .put (queryAppliedDirective , normalizedArgumentValues );
112117 }
113118 }
0 commit comments