@@ -265,6 +265,54 @@ function resolveThunk<T>(thunk: Thunk<T>): T {
265
265
return typeof thunk === 'function' ? thunk ( ) : thunk ;
266
266
}
267
267
268
+ export class GraphQLAppliedDirectives {
269
+ _appliedDirectivesConfig : GraphQLAppliedDirectivesConfig ;
270
+ _argsMap : GraphQLDirectiveArgsMap ;
271
+
272
+ constructor ( config : GraphQLAppliedDirectivesConfig ) {
273
+ invariant (
274
+ isPlainObj ( config ) ,
275
+ 'Applied directives must be an object with directive names as keys.'
276
+ ) ;
277
+
278
+ this . _appliedDirectivesConfig = config ;
279
+ this . _argsMap = { } ;
280
+ }
281
+
282
+ isApplied(directiveName: string): boolean {
283
+ return Boolean ( this . _appliedDirectivesConfig [ directiveName ] ) ;
284
+ }
285
+
286
+ getAppliedDirectives(): Array< string > {
287
+ return Object . keys ( this . _appliedDirectivesConfig ) ;
288
+ }
289
+
290
+ getDirectiveArgs(directiveName: string): ?{ [ argName : string ] : any } {
291
+ if ( this . _argsMap [ directiveName ] ) {
292
+ return this . _argsMap [ directiveName ] ;
293
+ }
294
+ const argsThunk = this._appliedDirectivesConfig[directiveName];
295
+ const args = resolveThunk(argsThunk);
296
+ if (!args) {
297
+ return null ;
298
+ }
299
+ invariant(
300
+ isPlainObj(args),
301
+ `@${ directiveName } args must be an object with argument names as keys ` +
302
+ 'or a function which returns such an object.'
303
+ );
304
+ this._argsMap[directiveName] = args;
305
+ return args;
306
+ }
307
+ }
308
+
309
+ type GraphQLDirectiveArgsMap = {
310
+ [ key : string ] : { [ argName : string ] : any }
311
+ } ;
312
+
313
+ type GraphQLAppliedDirectivesConfig = {
314
+ [ key : string ] : Thunk < * >
315
+ } ;
268
316
269
317
/**
270
318
* Scalar Type Definition
@@ -286,13 +334,15 @@ function resolveThunk<T>(thunk: Thunk<T>): T {
286
334
export class GraphQLScalarType {
287
335
name : string ;
288
336
description: ?string ;
337
+ appliedDirectives: ?GraphQLAppliedDirectives ;
289
338
290
339
_scalarConfig: GraphQLScalarTypeConfig < * , * > ;
291
340
292
341
constructor ( config : GraphQLScalarTypeConfig < * , * > ) {
293
342
assertValidName ( config . name ) ;
294
343
this . name = config . name ;
295
344
this . description = config . description ;
345
+ this . appliedDirectives = config . appliedDirectives ;
296
346
invariant (
297
347
typeof config . serialize === 'function' ,
298
348
`${ this . name } must provide "serialize" function. If this custom Scalar ` +
@@ -344,6 +394,7 @@ GraphQLScalarType.prototype.toJSON =
344
394
export type GraphQLScalarTypeConfig < TInternal , TExternal > = {
345
395
name : string ;
346
396
description ?: ?string ;
397
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
347
398
serialize : ( value : mixed ) => ?TExternal ;
348
399
parseValue ?: ( value : mixed ) => ?TInternal ;
349
400
parseLiteral ?: ( valueNode : ValueNode ) => ?TInternal ;
@@ -391,6 +442,7 @@ export type GraphQLScalarTypeConfig<TInternal, TExternal> = {
391
442
export class GraphQLObjectType {
392
443
name : string ;
393
444
description : ?string ;
445
+ appliedDirectives : ?GraphQLAppliedDirectives ;
394
446
isTypeOf : ?GraphQLIsTypeOfFn < * , * > ;
395
447
396
448
_typeConfig : GraphQLObjectTypeConfig < * , * > ;
@@ -401,6 +453,7 @@ export class GraphQLObjectType {
401
453
assertValidName ( config . name , config . isIntrospection ) ;
402
454
this . name = config . name ;
403
455
this . description = config . description ;
456
+ this . appliedDirectives = config . appliedDirectives ;
404
457
if ( config . isTypeOf ) {
405
458
invariant (
406
459
typeof config . isTypeOf === 'function' ,
@@ -535,7 +588,8 @@ function defineFieldMap<TSource, TContext>(
535
588
name : argName ,
536
589
description : arg . description === undefined ? null : arg . description ,
537
590
type : arg . type ,
538
- defaultValue : arg . defaultValue
591
+ defaultValue : arg . defaultValue ,
592
+ appliedDirectives : arg . appliedDirectives ,
539
593
} ;
540
594
} ) ;
541
595
}
@@ -560,6 +614,7 @@ export type GraphQLObjectTypeConfig<TSource, TContext> = {
560
614
isTypeOf ?: ?GraphQLIsTypeOfFn < TSource , TContext > ;
561
615
description ?: ?string ;
562
616
isIntrospection ?: boolean ;
617
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
563
618
} ;
564
619
565
620
export type GraphQLTypeResolver < TSource , TContext > = (
@@ -602,6 +657,7 @@ export type GraphQLFieldConfig<TSource, TContext> = {
602
657
resolve ?: GraphQLFieldResolver < TSource , TContext > ;
603
658
deprecationReason ?: ?string ;
604
659
description ?: ?string ;
660
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
605
661
} ;
606
662
607
663
export type GraphQLFieldConfigArgumentMap = {
@@ -612,6 +668,7 @@ export type GraphQLArgumentConfig = {
612
668
type : GraphQLInputType ;
613
669
defaultValue ?: mixed ;
614
670
description ?: ?string ;
671
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
615
672
} ;
616
673
617
674
export type GraphQLFieldConfigMap < TSource , TContext > = {
@@ -626,13 +683,15 @@ export type GraphQLField<TSource, TContext> = {
626
683
resolve ? : GraphQLFieldResolver < TSource , TContext > ;
627
684
isDeprecated ?: boolean ;
628
685
deprecationReason ?: ?string ;
686
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
629
687
} ;
630
688
631
689
export type GraphQLArgument = {
632
690
name : string ;
633
691
type : GraphQLInputType ;
634
692
defaultValue ?: mixed ;
635
693
description ?: ?string ;
694
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
636
695
} ;
637
696
638
697
export type GraphQLFieldMap < TSource , TContext > = {
@@ -662,6 +721,7 @@ export type GraphQLFieldMap<TSource, TContext> = {
662
721
export class GraphQLInterfaceType {
663
722
name : string ;
664
723
description : ?string ;
724
+ appliedDirectives : ?GraphQLAppliedDirectives ;
665
725
resolveType : ?GraphQLTypeResolver < * , * > ;
666
726
667
727
_typeConfig : GraphQLInterfaceTypeConfig < * , * > ;
@@ -671,6 +731,7 @@ export class GraphQLInterfaceType {
671
731
assertValidName ( config . name ) ;
672
732
this . name = config . name ;
673
733
this . description = config . description ;
734
+ this . appliedDirectives = config . appliedDirectives ;
674
735
if ( config . resolveType ) {
675
736
invariant (
676
737
typeof config . resolveType === 'function' ,
@@ -708,7 +769,8 @@ export type GraphQLInterfaceTypeConfig<TSource, TContext> = {
708
769
* Object type.
709
770
*/
710
771
resolveType ?: ?GraphQLTypeResolver < TSource , TContext> ,
711
- description ?: ?string
772
+ description ?: ?string ,
773
+ appliedDirectives ?: ?GraphQLAppliedDirectives ,
712
774
} ;
713
775
714
776
@@ -739,6 +801,7 @@ export type GraphQLInterfaceTypeConfig<TSource, TContext> = {
739
801
export class GraphQLUnionType {
740
802
name : string ;
741
803
description : ?string ;
804
+ appliedDirectives : ?GraphQLAppliedDirectives ;
742
805
resolveType : ?GraphQLTypeResolver < * , * > ;
743
806
744
807
_typeConfig : GraphQLUnionTypeConfig < * , * > ;
@@ -749,6 +812,7 @@ export class GraphQLUnionType {
749
812
assertValidName ( config . name ) ;
750
813
this . name = config . name ;
751
814
this . description = config . description ;
815
+ this . appliedDirectives = config . appliedDirectives ;
752
816
if ( config . resolveType ) {
753
817
invariant (
754
818
typeof config . resolveType === 'function' ,
@@ -819,6 +883,7 @@ export type GraphQLUnionTypeConfig<TSource, TContext> = {
819
883
*/
820
884
resolveType ?: ?GraphQLTypeResolver < TSource , TContext > ;
821
885
description ?: ?string ;
886
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
822
887
} ;
823
888
824
889
@@ -847,6 +912,7 @@ export type GraphQLUnionTypeConfig<TSource, TContext> = {
847
912
export class GraphQLEnumType /* <T> */ {
848
913
name : string ;
849
914
description : ?string ;
915
+ appliedDirectives : ?GraphQLAppliedDirectives ;
850
916
851
917
_enumConfig : GraphQLEnumTypeConfig /* <T> */ ;
852
918
_values : Array < GraphQLEnumValue /* <T> */ > ;
@@ -857,6 +923,7 @@ export class GraphQLEnumType/* <T> */ {
857
923
this . name = config . name ;
858
924
assertValidName ( config . name , config . isIntrospection ) ;
859
925
this . description = config . description ;
926
+ this . appliedDirectives = config . appliedDirectives ;
860
927
this . _values = defineEnumValues ( this , config . values ) ;
861
928
this . _enumConfig = config ;
862
929
}
@@ -958,6 +1025,7 @@ function defineEnumValues(
958
1025
description : value . description ,
959
1026
isDeprecated : Boolean ( value . deprecationReason ) ,
960
1027
deprecationReason : value . deprecationReason ,
1028
+ appliedDirectives : value . appliedDirectives ,
961
1029
value : isNullish ( value . value ) ? valueName : value . value ,
962
1030
} ;
963
1031
} ) ;
@@ -967,6 +1035,7 @@ export type GraphQLEnumTypeConfig/* <T> */ = {
967
1035
name : string ;
968
1036
values : GraphQLEnumValueConfigMap /* <T> */ ;
969
1037
description ?: ?string ;
1038
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
970
1039
isIntrospection ?: boolean ;
971
1040
} ;
972
1041
@@ -978,13 +1047,15 @@ export type GraphQLEnumValueConfig/* <T> */ = {
978
1047
value ?: any /* T */ ;
979
1048
deprecationReason ?: ?string ;
980
1049
description ?: ?string ;
1050
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
981
1051
} ;
982
1052
983
1053
export type GraphQLEnumValue /* <T> */ = {
984
1054
name : string ;
985
1055
description : ?string ;
986
1056
isDeprecated ?: boolean ;
987
1057
deprecationReason : ?string ;
1058
+ appliedDirectives : ?GraphQLAppliedDirectives ;
988
1059
value : any /* T */ ;
989
1060
} ;
990
1061
@@ -1013,6 +1084,7 @@ export type GraphQLEnumValue/* <T> */ = {
1013
1084
export class GraphQLInputObjectType {
1014
1085
name : string ;
1015
1086
description : ?string ;
1087
+ appliedDirectives : ?GraphQLAppliedDirectives ;
1016
1088
1017
1089
_typeConfig : GraphQLInputObjectTypeConfig ;
1018
1090
_fields : GraphQLInputFieldMap ;
@@ -1021,6 +1093,7 @@ export class GraphQLInputObjectType {
1021
1093
assertValidName ( config . name ) ;
1022
1094
this . name = config . name ;
1023
1095
this . description = config . description ;
1096
+ this . appliedDirectives = config . appliedDirectives ;
1024
1097
this . _typeConfig = config ;
1025
1098
}
1026
1099
@@ -1080,12 +1153,14 @@ export type GraphQLInputObjectTypeConfig = {
1080
1153
name : string ;
1081
1154
fields : Thunk < GraphQLInputFieldConfigMap > ;
1082
1155
description ?: ?string ;
1156
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
1083
1157
} ;
1084
1158
1085
1159
export type GraphQLInputFieldConfig = {
1086
1160
type : GraphQLInputType ;
1087
1161
defaultValue ?: mixed ;
1088
1162
description ?: ?string ;
1163
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
1089
1164
} ;
1090
1165
1091
1166
export type GraphQLInputFieldConfigMap = {
@@ -1097,6 +1172,7 @@ export type GraphQLInputField = {
1097
1172
type : GraphQLInputType ;
1098
1173
defaultValue ?: mixed ;
1099
1174
description ?: ?string ;
1175
+ appliedDirectives ?: ?GraphQLAppliedDirectives ;
1100
1176
} ;
1101
1177
1102
1178
export type GraphQLInputFieldMap = {
0 commit comments