88use GraphQL \Language \AST \DocumentNode ;
99use GraphQL \Language \AST \FieldNode ;
1010use GraphQL \Language \AST \FragmentDefinitionNode ;
11+ use GraphQL \Language \AST \FragmentSpreadNode ;
12+ use GraphQL \Language \AST \InlineFragmentNode ;
1113use GraphQL \Language \AST \NodeKind ;
1214use GraphQL \Language \AST \OperationDefinitionNode ;
1315use GraphQL \Language \AST \SelectionSetNode ;
@@ -508,7 +510,7 @@ private function collectFields(
508510 foreach ($ selectionSet ->selections as $ selection ) {
509511 switch ($ selection ->kind ) {
510512 case NodeKind::FIELD :
511- if (!$ this ->shouldIncludeNode ($ selection-> directives )) {
513+ if (!$ this ->shouldIncludeNode ($ selection )) {
512514 continue ;
513515 }
514516 $ name = self ::getFieldEntryKey ($ selection );
@@ -518,7 +520,7 @@ private function collectFields(
518520 $ fields [$ name ][] = $ selection ;
519521 break ;
520522 case NodeKind::INLINE_FRAGMENT :
521- if (!$ this ->shouldIncludeNode ($ selection-> directives ) ||
523+ if (!$ this ->shouldIncludeNode ($ selection ) ||
522524 !$ this ->doesFragmentConditionMatch ($ selection , $ runtimeType )
523525 ) {
524526 continue ;
@@ -532,7 +534,7 @@ private function collectFields(
532534 break ;
533535 case NodeKind::FRAGMENT_SPREAD :
534536 $ fragName = $ selection ->name ->value ;
535- if (!empty ($ visitedFragmentNames [$ fragName ]) || !$ this ->shouldIncludeNode ($ selection-> directives )) {
537+ if (!empty ($ visitedFragmentNames [$ fragName ]) || !$ this ->shouldIncludeNode ($ selection )) {
536538 continue ;
537539 }
538540 $ visitedFragmentNames [$ fragName ] = true ;
@@ -558,43 +560,35 @@ private function collectFields(
558560 * Determines if a field should be included based on the @include and @skip
559561 * directives, where @skip has higher precedence than @include.
560562 *
561- * @param $directives
563+ * @param FragmentSpreadNode | FieldNode | InlineFragmentNode $node
562564 * @return bool
563565 */
564- private function shouldIncludeNode ($ directives )
566+ private function shouldIncludeNode ($ node )
565567 {
566- $ exeContext = $ this ->exeContext ;
568+ $ variableValues = $ this ->exeContext -> variableValues ;
567569 $ skipDirective = Directive::skipDirective ();
568- $ includeDirective = Directive::includeDirective ();
569570
570- /** @var \GraphQL\Language\AST\DirectiveNode $skipNode */
571- $ skipNode = $ directives
572- ? Utils::find ($ directives , function (\GraphQL \Language \AST \DirectiveNode $ directive ) use ($ skipDirective ) {
573- return $ directive ->name ->value === $ skipDirective ->name ;
574- })
575- : null ;
571+ $ skip = Values::getDirectiveValues (
572+ $ skipDirective ,
573+ $ node ,
574+ $ variableValues
575+ );
576576
577- if ($ skipNode ) {
578- $ argValues = Values::getArgumentValues ($ skipDirective , $ skipNode , $ exeContext ->variableValues );
579- if (isset ($ argValues ['if ' ]) && $ argValues ['if ' ] === true ) {
580- return false ;
581- }
577+ if (isset ($ skip ['if ' ]) && $ skip ['if ' ] === true ) {
578+ return false ;
582579 }
583580
584- /** @var \GraphQL\Language\AST\DirectiveNode $includeNode */
585- $ includeNode = $ directives
586- ? Utils::find ($ directives , function (\GraphQL \Language \AST \DirectiveNode $ directive ) use ($ includeDirective ) {
587- return $ directive ->name ->value === $ includeDirective ->name ;
588- })
589- : null ;
581+ $ includeDirective = Directive::includeDirective ();
590582
591- if ($ includeNode ) {
592- $ argValues = Values::getArgumentValues ($ includeDirective , $ includeNode , $ exeContext ->variableValues );
593- if (isset ($ argValues ['if ' ]) && $ argValues ['if ' ] === false ) {
594- return false ;
595- }
596- }
583+ $ include = Values::getDirectiveValues (
584+ $ includeDirective ,
585+ $ node ,
586+ $ variableValues
587+ );
597588
589+ if (isset ($ include ['if ' ]) && $ include ['if ' ] === false ) {
590+ return false ;
591+ }
598592 return true ;
599593 }
600594
0 commit comments