@@ -272,6 +272,54 @@ function resolveThunk<T>(thunk: Thunk<T>): T {
272
272
return typeof thunk === 'function' ? thunk ( ) : thunk ;
273
273
}
274
274
275
+ export class GraphQLAppliedDirectives {
276
+ _appliedDirectivesConfig : GraphQLAppliedDirectivesConfig ;
277
+ _argsMap : GraphQLDirectiveArgsMap ;
278
+
279
+ constructor ( config : GraphQLAppliedDirectivesConfig ) {
280
+ invariant (
281
+ isPlainObj ( config ) ,
282
+ 'Applied directives must be an object with directive names as keys.'
283
+ ) ;
284
+
285
+ this . _appliedDirectivesConfig = config ;
286
+ this . _argsMap = { } ;
287
+ }
288
+
289
+ isApplied(directiveName: string): boolean {
290
+ return Boolean ( this . _appliedDirectivesConfig [ directiveName ] ) ;
291
+ }
292
+
293
+ getAppliedDirectives(): Array< string > {
294
+ return Object . keys ( this . _appliedDirectivesConfig ) ;
295
+ }
296
+
297
+ getDirectiveArgs(directiveName: string): ?{ [ argName : string ] : any } {
298
+ if ( this . _argsMap [ directiveName ] ) {
299
+ return this . _argsMap [ directiveName ] ;
300
+ }
301
+ const argsThunk = this._appliedDirectivesConfig[directiveName];
302
+ const args = resolveThunk(argsThunk);
303
+ if (!args) {
304
+ return null ;
305
+ }
306
+ invariant(
307
+ isPlainObj(args),
308
+ `@${ directiveName } args must be an object with argument names as keys ` +
309
+ 'or a function which returns such an object.'
310
+ );
311
+ this._argsMap[directiveName] = args;
312
+ return args;
313
+ }
314
+ }
315
+
316
+ type GraphQLDirectiveArgsMap = {
317
+ [ key : string ] : { [ argName : string ] : any }
318
+ } ;
319
+
320
+ type GraphQLAppliedDirectivesConfig = {
321
+ [ key : string ] : Thunk < * >
322
+ } ;
275
323
276
324
/**
277
325
* Scalar Type Definition
@@ -293,13 +341,15 @@ function resolveThunk<T>(thunk: Thunk<T>): T {
293
341
export class GraphQLScalarType {
294
342
name : string ;
295
343
description: ?string ;
344
+ appliedDirectives: ?GraphQLAppliedDirectives ;
296
345
297
346
_scalarConfig: GraphQLScalarTypeConfig < * , * > ;
298
347
299
348
constructor ( config : GraphQLScalarTypeConfig < * , * > ) {
300
349
assertValidName ( config . name ) ;
301
350
this . name = config . name ;
302
351
this . description = config . description ;
352
+ this . appliedDirectives = config . appliedDirectives ;
303
353
invariant (
304
354
typeof config . serialize === 'function' ,
305
355
`${ this . name } must provide "serialize" function. If this custom Scalar ` +
@@ -351,6 +401,7 @@ GraphQLScalarType.prototype.toJSON =
351
401
export type GraphQLScalarTypeConfig < TInternal , TExternal > = {
352
402
name : string ;
353
403
description ?: ?string ;
404
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
354
405
serialize : ( value : mixed ) => ?TExternal ;
355
406
parseValue ?: ( value : mixed ) => ?TInternal ;
356
407
parseLiteral ?: ( valueNode : ValueNode ) => ?TInternal ;
@@ -398,6 +449,7 @@ export type GraphQLScalarTypeConfig<TInternal, TExternal> = {
398
449
export class GraphQLObjectType {
399
450
name : string ;
400
451
description : ?string ;
452
+ appliedDirectives : ?GraphQLAppliedDirectives ;
401
453
isTypeOf : ?GraphQLIsTypeOfFn < * , * > ;
402
454
403
455
_typeConfig : GraphQLObjectTypeConfig < * , * > ;
@@ -408,6 +460,7 @@ export class GraphQLObjectType {
408
460
assertValidName ( config . name , config . isIntrospection ) ;
409
461
this . name = config . name ;
410
462
this . description = config . description ;
463
+ this . appliedDirectives = config . appliedDirectives ;
411
464
if ( config . isTypeOf ) {
412
465
invariant (
413
466
typeof config . isTypeOf === 'function' ,
@@ -549,7 +602,8 @@ function defineFieldMap<TSource, TContext>(
549
602
name : argName ,
550
603
description : arg . description === undefined ? null : arg . description ,
551
604
type : arg . type ,
552
- defaultValue : arg . defaultValue
605
+ defaultValue : arg . defaultValue ,
606
+ appliedDirectives : arg . appliedDirectives ,
553
607
} ;
554
608
} ) ;
555
609
}
@@ -574,6 +628,7 @@ export type GraphQLObjectTypeConfig<TSource, TContext> = {
574
628
isTypeOf ?: ?GraphQLIsTypeOfFn < TSource , TContext > ;
575
629
description ?: ?string ;
576
630
isIntrospection ?: boolean ;
631
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
577
632
} ;
578
633
579
634
export type GraphQLTypeResolver < TSource , TContext > = (
@@ -616,6 +671,7 @@ export type GraphQLFieldConfig<TSource, TContext> = {
616
671
resolve ?: GraphQLFieldResolver < TSource , TContext > ;
617
672
deprecationReason ?: ?string ;
618
673
description ?: ?string ;
674
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
619
675
} ;
620
676
621
677
export type GraphQLFieldConfigArgumentMap = {
@@ -626,6 +682,7 @@ export type GraphQLArgumentConfig = {
626
682
type : GraphQLInputType ;
627
683
defaultValue ?: mixed ;
628
684
description ?: ?string ;
685
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
629
686
} ;
630
687
631
688
export type GraphQLFieldConfigMap < TSource , TContext > = {
@@ -640,13 +697,15 @@ export type GraphQLField<TSource, TContext> = {
640
697
resolve ? : GraphQLFieldResolver < TSource , TContext > ;
641
698
isDeprecated ?: boolean ;
642
699
deprecationReason ?: ?string ;
700
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
643
701
} ;
644
702
645
703
export type GraphQLArgument = {
646
704
name : string ;
647
705
type : GraphQLInputType ;
648
706
defaultValue ?: mixed ;
649
707
description ?: ?string ;
708
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
650
709
} ;
651
710
652
711
export type GraphQLFieldMap < TSource , TContext > = {
@@ -676,6 +735,7 @@ export type GraphQLFieldMap<TSource, TContext> = {
676
735
export class GraphQLInterfaceType {
677
736
name : string ;
678
737
description : ?string ;
738
+ appliedDirectives : ?GraphQLAppliedDirectives ;
679
739
resolveType : ?GraphQLTypeResolver < * , * > ;
680
740
681
741
_typeConfig : GraphQLInterfaceTypeConfig < * , * > ;
@@ -685,6 +745,7 @@ export class GraphQLInterfaceType {
685
745
assertValidName ( config . name ) ;
686
746
this . name = config . name ;
687
747
this . description = config . description ;
748
+ this . appliedDirectives = config . appliedDirectives ;
688
749
if ( config . resolveType ) {
689
750
invariant (
690
751
typeof config . resolveType === 'function' ,
@@ -722,7 +783,8 @@ export type GraphQLInterfaceTypeConfig<TSource, TContext> = {
722
783
* Object type.
723
784
*/
724
785
resolveType ?: ?GraphQLTypeResolver < TSource , TContext> ,
725
- description ?: ?string
786
+ description ?: ?string ,
787
+ appliedDirectives ?: ?GraphQLAppliedDirectives ,
726
788
} ;
727
789
728
790
@@ -753,6 +815,7 @@ export type GraphQLInterfaceTypeConfig<TSource, TContext> = {
753
815
export class GraphQLUnionType {
754
816
name : string ;
755
817
description : ?string ;
818
+ appliedDirectives : ?GraphQLAppliedDirectives ;
756
819
resolveType : ?GraphQLTypeResolver < * , * > ;
757
820
758
821
_typeConfig : GraphQLUnionTypeConfig < * , * > ;
@@ -763,6 +826,7 @@ export class GraphQLUnionType {
763
826
assertValidName ( config . name ) ;
764
827
this . name = config . name ;
765
828
this . description = config . description ;
829
+ this . appliedDirectives = config . appliedDirectives ;
766
830
if ( config . resolveType ) {
767
831
invariant (
768
832
typeof config . resolveType === 'function' ,
@@ -839,6 +903,7 @@ export type GraphQLUnionTypeConfig<TSource, TContext> = {
839
903
*/
840
904
resolveType ?: ?GraphQLTypeResolver < TSource , TContext > ;
841
905
description ?: ?string ;
906
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
842
907
} ;
843
908
844
909
@@ -867,6 +932,7 @@ export type GraphQLUnionTypeConfig<TSource, TContext> = {
867
932
export class GraphQLEnumType /* <T> */ {
868
933
name : string ;
869
934
description : ?string ;
935
+ appliedDirectives : ?GraphQLAppliedDirectives ;
870
936
871
937
_enumConfig : GraphQLEnumTypeConfig /* <T> */ ;
872
938
_values : Array < GraphQLEnumValue /* <T> */ > ;
@@ -877,6 +943,7 @@ export class GraphQLEnumType/* <T> */ {
877
943
this . name = config . name ;
878
944
assertValidName ( config . name , config . isIntrospection ) ;
879
945
this . description = config . description ;
946
+ this . appliedDirectives = config . appliedDirectives ;
880
947
this . _values = defineEnumValues ( this , config . values ) ;
881
948
this . _enumConfig = config ;
882
949
}
@@ -983,6 +1050,7 @@ function defineEnumValues(
983
1050
description : value . description ,
984
1051
isDeprecated : Boolean ( value . deprecationReason ) ,
985
1052
deprecationReason : value . deprecationReason ,
1053
+ appliedDirectives : value . appliedDirectives ,
986
1054
value : value . hasOwnProperty ( 'value' ) ? value . value : valueName ,
987
1055
} ;
988
1056
} ) ;
@@ -992,6 +1060,7 @@ export type GraphQLEnumTypeConfig/* <T> */ = {
992
1060
name : string ;
993
1061
values : GraphQLEnumValueConfigMap /* <T> */ ;
994
1062
description ?: ?string ;
1063
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
995
1064
isIntrospection ?: boolean ;
996
1065
} ;
997
1066
@@ -1003,13 +1072,15 @@ export type GraphQLEnumValueConfig/* <T> */ = {
1003
1072
value ?: any /* T */ ;
1004
1073
deprecationReason ?: ?string ;
1005
1074
description ?: ?string ;
1075
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
1006
1076
} ;
1007
1077
1008
1078
export type GraphQLEnumValue /* <T> */ = {
1009
1079
name : string ;
1010
1080
description : ?string ;
1011
1081
isDeprecated ?: boolean ;
1012
1082
deprecationReason : ?string ;
1083
+ appliedDirectives : ?GraphQLAppliedDirectives ;
1013
1084
value : any /* T */ ;
1014
1085
} ;
1015
1086
@@ -1038,6 +1109,7 @@ export type GraphQLEnumValue/* <T> */ = {
1038
1109
export class GraphQLInputObjectType {
1039
1110
name : string ;
1040
1111
description : ?string ;
1112
+ appliedDirectives : ?GraphQLAppliedDirectives ;
1041
1113
1042
1114
_typeConfig : GraphQLInputObjectTypeConfig ;
1043
1115
_fields : GraphQLInputFieldMap ;
@@ -1046,6 +1118,7 @@ export class GraphQLInputObjectType {
1046
1118
assertValidName ( config . name ) ;
1047
1119
this . name = config . name ;
1048
1120
this . description = config . description ;
1121
+ this . appliedDirectives = config . appliedDirectives ;
1049
1122
this . _typeConfig = config ;
1050
1123
}
1051
1124
@@ -1105,12 +1178,14 @@ export type GraphQLInputObjectTypeConfig = {
1105
1178
name : string ;
1106
1179
fields : Thunk < GraphQLInputFieldConfigMap > ;
1107
1180
description ?: ?string ;
1181
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
1108
1182
} ;
1109
1183
1110
1184
export type GraphQLInputFieldConfig = {
1111
1185
type : GraphQLInputType ;
1112
1186
defaultValue ?: mixed ;
1113
1187
description ?: ?string ;
1188
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
1114
1189
} ;
1115
1190
1116
1191
export type GraphQLInputFieldConfigMap = {
@@ -1122,6 +1197,7 @@ export type GraphQLInputField = {
1122
1197
type : GraphQLInputType ;
1123
1198
defaultValue ?: mixed ;
1124
1199
description ?: ?string ;
1200
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
1125
1201
} ;
1126
1202
1127
1203
export type GraphQLInputFieldMap = {
0 commit comments