11
11
import { forEach , isCollection } from 'iterall' ;
12
12
13
13
import { GraphQLError , locatedError } from '../error' ;
14
- import find from '../jsutils/find' ;
15
14
import invariant from '../jsutils/invariant' ;
16
15
import isNullish from '../jsutils/isNullish' ;
17
16
import { typeFromAST } from '../utilities/typeFromAST' ;
18
17
import * as Kind from '../language/kinds' ;
19
- import { getVariableValues , getArgumentValues } from './values' ;
18
+ import {
19
+ getVariableValues ,
20
+ getArgumentValues ,
21
+ getDirectiveValues ,
22
+ } from './values' ;
20
23
import {
21
24
GraphQLObjectType ,
22
25
GraphQLList ,
@@ -44,11 +47,11 @@ import {
44
47
GraphQLSkipDirective ,
45
48
} from '../type/directives' ;
46
49
import type {
47
- DirectiveNode ,
48
50
DocumentNode ,
49
51
OperationDefinitionNode ,
50
52
SelectionSetNode ,
51
53
FieldNode ,
54
+ FragmentSpreadNode ,
52
55
InlineFragmentNode ,
53
56
FragmentDefinitionNode ,
54
57
} from '../language/ast' ;
@@ -512,7 +515,7 @@ export function collectFields(
512
515
const selection = selectionSet . selections [ i ] ;
513
516
switch ( selection . kind ) {
514
517
case Kind . FIELD :
515
- if ( ! shouldIncludeNode ( exeContext , selection . directives ) ) {
518
+ if ( ! shouldIncludeNode ( exeContext , selection ) ) {
516
519
continue ;
517
520
}
518
521
const name = getFieldEntryKey ( selection ) ;
@@ -522,7 +525,7 @@ export function collectFields(
522
525
fields [ name ] . push ( selection ) ;
523
526
break ;
524
527
case Kind . INLINE_FRAGMENT :
525
- if ( ! shouldIncludeNode ( exeContext , selection . directives ) ||
528
+ if ( ! shouldIncludeNode ( exeContext , selection ) ||
526
529
! doesFragmentConditionMatch ( exeContext , selection , runtimeType ) ) {
527
530
continue ;
528
531
}
@@ -537,7 +540,7 @@ export function collectFields(
537
540
case Kind . FRAGMENT_SPREAD :
538
541
const fragName = selection . name . value ;
539
542
if ( visitedFragmentNames [ fragName ] ||
540
- ! shouldIncludeNode ( exeContext , selection . directives ) ) {
543
+ ! shouldIncludeNode ( exeContext , selection ) ) {
541
544
continue ;
542
545
}
543
546
visitedFragmentNames [ fragName ] = true ;
@@ -565,38 +568,25 @@ export function collectFields(
565
568
*/
566
569
function shouldIncludeNode (
567
570
exeContext : ExecutionContext ,
568
- directives : ? Array < DirectiveNode >
571
+ node : FragmentSpreadNode | FieldNode | InlineFragmentNode ,
569
572
) : boolean {
570
- const skipNode = directives && find (
571
- directives ,
572
- directive => directive . name . value === GraphQLSkipDirective . name
573
+ const skip = getDirectiveValues (
574
+ GraphQLSkipDirective ,
575
+ node ,
576
+ exeContext . variableValues
573
577
) ;
574
- if ( skipNode ) {
575
- const { if : skipIf } = getArgumentValues (
576
- GraphQLSkipDirective ,
577
- skipNode ,
578
- exeContext . variableValues
579
- ) ;
580
- if ( skipIf === true ) {
581
- return false ;
582
- }
578
+ if ( skip && skip . if === true ) {
579
+ return false ;
583
580
}
584
581
585
- const includeNode = directives && find (
586
- directives ,
587
- directive => directive . name . value === GraphQLIncludeDirective . name
582
+ const include = getDirectiveValues(
583
+ GraphQLIncludeDirective,
584
+ node,
585
+ exeContext.variableValues
588
586
);
589
- if ( includeNode ) {
590
- const { if : includeIf } = getArgumentValues (
591
- GraphQLIncludeDirective ,
592
- includeNode ,
593
- exeContext . variableValues
594
- ) ;
595
- if ( includeIf === false ) {
596
- return false ;
597
- }
587
+ if (include && include . if === false ) {
588
+ return false ;
598
589
}
599
-
600
590
return true;
601
591
}
602
592
0 commit comments