@@ -38,83 +38,81 @@ public FieldCollector() {
3838 /**
3939 * Given a list of fields this will collect the sub-field selections and return it as a map
4040 *
41- * @param executionContext the {@link ExecutionContext} in play
42- * @param objectType the graphql object type in context
43- * @param fields the list of fields to collect for
41+ * @param parameters the parameters to this method
42+ * @param fields the list of fields to collect for
4443 *
4544 * @return a map of the sub field selections
4645 */
47- public Map <String , List <Field >> collectFields (ExecutionContext executionContext , GraphQLObjectType objectType , List <Field > fields ) {
46+ public Map <String , List <Field >> collectFields (FieldCollectorParameters parameters , List <Field > fields ) {
4847 Map <String , List <Field >> subFields = new LinkedHashMap <>();
4948 List <String > visitedFragments = new ArrayList <>();
5049 for (Field field : fields ) {
5150 if (field .getSelectionSet () == null ) {
5251 continue ;
5352 }
54- this .collectFields (executionContext , objectType , field .getSelectionSet (), visitedFragments , subFields );
53+ this .collectFields (parameters , field .getSelectionSet (), visitedFragments , subFields );
5554 }
5655 return subFields ;
5756 }
5857
5958 /**
6059 * Given a selection set this will collect the sub-field selections and return it as a map
6160 *
62- * @param executionContext the {@link ExecutionContext} in play
63- * @param objectType the graphql object type in context
64- * @param selectionSet the selection set to collect on
61+ * @param parameters the parameters to this method
62+ * @param selectionSet the selection set to collect on
6563 *
6664 * @return a map of the sub field selections
6765 */
68- public Map <String , List <Field >> collectFields (ExecutionContext executionContext , GraphQLObjectType objectType , SelectionSet selectionSet ) {
66+ public Map <String , List <Field >> collectFields (FieldCollectorParameters parameters , SelectionSet selectionSet ) {
6967 Map <String , List <Field >> subFields = new LinkedHashMap <>();
7068 List <String > visitedFragments = new ArrayList <>();
71- this .collectFields (executionContext , objectType , selectionSet , visitedFragments , subFields );
69+ this .collectFields (parameters , selectionSet , visitedFragments , subFields );
7270 return subFields ;
7371 }
7472
7573
76- private void collectFields (ExecutionContext executionContext , GraphQLObjectType type , SelectionSet selectionSet , List <String > visitedFragments , Map <String , List <Field >> fields ) {
74+ private void collectFields (FieldCollectorParameters parameters , SelectionSet selectionSet , List <String > visitedFragments , Map <String , List <Field >> fields ) {
7775
7876 for (Selection selection : selectionSet .getSelections ()) {
7977 if (selection instanceof Field ) {
80- collectField (executionContext , fields , (Field ) selection );
78+ collectField (parameters , fields , (Field ) selection );
8179 } else if (selection instanceof InlineFragment ) {
82- collectInlineFragment (executionContext , type , visitedFragments , fields , (InlineFragment ) selection );
80+ collectInlineFragment (parameters , visitedFragments , fields , (InlineFragment ) selection );
8381 } else if (selection instanceof FragmentSpread ) {
84- collectFragmentSpread (executionContext , type , visitedFragments , fields , (FragmentSpread ) selection );
82+ collectFragmentSpread (parameters , visitedFragments , fields , (FragmentSpread ) selection );
8583 }
8684 }
8785 }
8886
89- private void collectFragmentSpread (ExecutionContext executionContext , GraphQLObjectType type , List <String > visitedFragments , Map <String , List <Field >> fields , FragmentSpread fragmentSpread ) {
87+ private void collectFragmentSpread (FieldCollectorParameters parameters , List <String > visitedFragments , Map <String , List <Field >> fields , FragmentSpread fragmentSpread ) {
9088 if (visitedFragments .contains (fragmentSpread .getName ())) {
9189 return ;
9290 }
93- if (!conditionalNodes .shouldInclude (executionContext , fragmentSpread .getDirectives ())) {
91+ if (!conditionalNodes .shouldInclude (parameters . getVariables () , fragmentSpread .getDirectives ())) {
9492 return ;
9593 }
9694 visitedFragments .add (fragmentSpread .getName ());
97- FragmentDefinition fragmentDefinition = executionContext . getFragment (fragmentSpread .getName ());
95+ FragmentDefinition fragmentDefinition = parameters . getFragmentsByName (). get (fragmentSpread .getName ());
9896
99- if (!conditionalNodes .shouldInclude (executionContext , fragmentDefinition .getDirectives ())) {
97+ if (!conditionalNodes .shouldInclude (parameters . getVariables () , fragmentDefinition .getDirectives ())) {
10098 return ;
10199 }
102- if (!doesFragmentConditionMatch (executionContext , fragmentDefinition , type )) {
100+ if (!doesFragmentConditionMatch (parameters , fragmentDefinition )) {
103101 return ;
104102 }
105- collectFields (executionContext , type , fragmentDefinition .getSelectionSet (), visitedFragments , fields );
103+ collectFields (parameters , fragmentDefinition .getSelectionSet (), visitedFragments , fields );
106104 }
107105
108- private void collectInlineFragment (ExecutionContext executionContext , GraphQLObjectType type , List <String > visitedFragments , Map <String , List <Field >> fields , InlineFragment inlineFragment ) {
109- if (!conditionalNodes .shouldInclude (executionContext , inlineFragment .getDirectives ()) ||
110- !doesFragmentConditionMatch (executionContext , inlineFragment , type )) {
106+ private void collectInlineFragment (FieldCollectorParameters parameters , List <String > visitedFragments , Map <String , List <Field >> fields , InlineFragment inlineFragment ) {
107+ if (!conditionalNodes .shouldInclude (parameters . getVariables () , inlineFragment .getDirectives ()) ||
108+ !doesFragmentConditionMatch (parameters , inlineFragment )) {
111109 return ;
112110 }
113- collectFields (executionContext , type , inlineFragment .getSelectionSet (), visitedFragments , fields );
111+ collectFields (parameters , inlineFragment .getSelectionSet (), visitedFragments , fields );
114112 }
115113
116- private void collectField (ExecutionContext executionContext , Map <String , List <Field >> fields , Field field ) {
117- if (!conditionalNodes .shouldInclude (executionContext , field .getDirectives ())) {
114+ private void collectField (FieldCollectorParameters parameters , Map <String , List <Field >> fields , Field field ) {
115+ if (!conditionalNodes .shouldInclude (parameters . getVariables () , field .getDirectives ())) {
118116 return ;
119117 }
120118 String name = getFieldEntryKey (field );
@@ -130,28 +128,29 @@ private String getFieldEntryKey(Field field) {
130128 }
131129
132130
133- private boolean doesFragmentConditionMatch (ExecutionContext executionContext , InlineFragment inlineFragment , GraphQLObjectType type ) {
131+ private boolean doesFragmentConditionMatch (FieldCollectorParameters parameters , InlineFragment inlineFragment ) {
134132 if (inlineFragment .getTypeCondition () == null ) {
135133 return true ;
136134 }
137135 GraphQLType conditionType ;
138- conditionType = getTypeFromAST (executionContext .getGraphQLSchema (), inlineFragment .getTypeCondition ());
139- return checkTypeCondition (executionContext , type , conditionType );
136+ conditionType = getTypeFromAST (parameters .getGraphQLSchema (), inlineFragment .getTypeCondition ());
137+ return checkTypeCondition (parameters , conditionType );
140138 }
141139
142- private boolean doesFragmentConditionMatch (ExecutionContext executionContext , FragmentDefinition fragmentDefinition , GraphQLObjectType type ) {
140+ private boolean doesFragmentConditionMatch (FieldCollectorParameters parameters , FragmentDefinition fragmentDefinition ) {
143141 GraphQLType conditionType ;
144- conditionType = getTypeFromAST (executionContext .getGraphQLSchema (), fragmentDefinition .getTypeCondition ());
145- return checkTypeCondition (executionContext , type , conditionType );
142+ conditionType = getTypeFromAST (parameters .getGraphQLSchema (), fragmentDefinition .getTypeCondition ());
143+ return checkTypeCondition (parameters , conditionType );
146144 }
147145
148- private boolean checkTypeCondition (ExecutionContext executionContext , GraphQLObjectType type , GraphQLType conditionType ) {
146+ private boolean checkTypeCondition (FieldCollectorParameters parameters , GraphQLType conditionType ) {
147+ GraphQLObjectType type = parameters .getObjectType ();
149148 if (conditionType .equals (type )) {
150149 return true ;
151150 }
152151
153152 if (conditionType instanceof GraphQLInterfaceType ) {
154- List <GraphQLObjectType > implementations = schemaUtil .findImplementations (executionContext .getGraphQLSchema (), (GraphQLInterfaceType ) conditionType );
153+ List <GraphQLObjectType > implementations = schemaUtil .findImplementations (parameters .getGraphQLSchema (), (GraphQLInterfaceType ) conditionType );
155154 return implementations .contains (type );
156155 } else if (conditionType instanceof GraphQLUnionType ) {
157156 return ((GraphQLUnionType ) conditionType ).getTypes ().contains (type );
0 commit comments