@@ -12,6 +12,8 @@ import inspect from '../jsutils/inspect';
12
12
import invariant from '../jsutils/invariant' ;
13
13
import isInvalid from '../jsutils/isInvalid' ;
14
14
import keyMap from '../jsutils/keyMap' ;
15
+ import keyValMap from '../jsutils/keyValMap' ;
16
+ import objectValues from '../jsutils/objectValues' ;
15
17
import type { ObjMap } from '../jsutils/ObjMap' ;
16
18
import { Kind } from '../language/kinds' ;
17
19
import { valueFromASTUntyped } from '../utilities/valueFromASTUntyped' ;
@@ -579,6 +581,17 @@ export class GraphQLScalarType {
579
581
: valueFromASTUntyped ( valueNode , variables ) ;
580
582
}
581
583
584
+ toConfig ( ) : GraphQLScalarTypeExactConfig < * , * > {
585
+ return {
586
+ name : this . name ,
587
+ description : this . description ,
588
+ serialize : this . _scalarConfig . serialize ,
589
+ parseValue : this . _scalarConfig . parseValue ,
590
+ parseLiteral : this . _scalarConfig . parseLiteral ,
591
+ astNode : this . astNode ,
592
+ } ;
593
+ }
594
+
582
595
toString ( ) : string {
583
596
return this . name ;
584
597
}
@@ -591,18 +604,31 @@ export class GraphQLScalarType {
591
604
GraphQLScalarType . prototype . toJSON = GraphQLScalarType . prototype . inspect =
592
605
GraphQLScalarType . prototype . toString ;
593
606
607
+ type GraphQLScalarSerializeFn < TExternal > = ( value : mixed ) => ?TExternal ;
608
+ type GraphQLScalarParseValueFn < TInternal > = ( value : mixed ) => ?TInternal ;
609
+ type GraphQLScalarParseLiteralFn < TInternal > = (
610
+ valueNode : ValueNode ,
611
+ variables : ?ObjMap < mixed > ,
612
+ ) => ?TInternal ;
613
+
594
614
export type GraphQLScalarTypeConfig < TInternal , TExternal > = {
595
615
name : string ,
596
616
description ?: ?string ,
597
617
astNode ?: ?ScalarTypeDefinitionNode ,
598
- serialize : ( value : mixed ) => ?TExternal ,
599
- parseValue ?: ( value : mixed ) => ?TInternal ,
600
- parseLiteral ?: (
601
- valueNode : ValueNode ,
602
- variables : ?ObjMap < mixed > ,
603
- ) => ?TInternal ,
618
+ serialize : GraphQLScalarSerializeFn < TExternal > ,
619
+ parseValue ?: GraphQLScalarParseValueFn < TInternal > ,
620
+ parseLiteral ?: GraphQLScalarParseLiteralFn < TInternal > ,
604
621
} ;
605
622
623
+ export type GraphQLScalarTypeExactConfig < TInternal , TExternal > = { |
624
+ name : string ,
625
+ description : ?string ,
626
+ astNode : ?ScalarTypeDefinitionNode ,
627
+ serialize : GraphQLScalarSerializeFn < TExternal > ,
628
+ parseValue ?: GraphQLScalarParseValueFn < TInternal > ,
629
+ parseLiteral ?: GraphQLScalarParseLiteralFn < TInternal > ,
630
+ | } ;
631
+
606
632
/**
607
633
* Object Type Definition
608
634
*
@@ -681,6 +707,18 @@ export class GraphQLObjectType {
681
707
) ;
682
708
}
683
709
710
+ toConfig ( ) : GraphQLObjectTypeExactConfig < * , * > {
711
+ return {
712
+ name : this . name ,
713
+ interfaces : this . getInterfaces ( ) ,
714
+ fields : fieldsToFieldsConfig ( this . getFields ( ) ) ,
715
+ isTypeOf : this . isTypeOf ,
716
+ description : this . description ,
717
+ astNode : this . astNode ,
718
+ extensionASTNodes : this . extensionASTNodes || [ ] ,
719
+ } ;
720
+ }
721
+
684
722
toString ( ) : string {
685
723
return this . name ;
686
724
}
@@ -773,6 +811,39 @@ function isValidResolver(resolver: mixed): boolean {
773
811
return resolver == null || typeof resolver === 'function' ;
774
812
}
775
813
814
+ function fieldsToFieldsConfig < TSource , TContext > (
815
+ fields : GraphQLFieldMap < TSource , TContext > ,
816
+ ) : GraphQLFieldExactConfigMap < TSource , TContext > {
817
+ return keyValMap (
818
+ objectValues ( fields ) ,
819
+ field => field . name ,
820
+ field => ( {
821
+ type : field . type ,
822
+ args : argsToArgsConfig ( field . args ) ,
823
+ resolve : field . resolve ,
824
+ subscribe : field . subscribe ,
825
+ deprecationReason : field . deprecationReason ,
826
+ description : field . description ,
827
+ astNode : field . astNode ,
828
+ } ) ,
829
+ ) ;
830
+ }
831
+
832
+ export function argsToArgsConfig (
833
+ args : Array < GraphQLArgument > ,
834
+ ) : GraphQLFieldExactConfigArgumentMap {
835
+ return keyValMap (
836
+ args ,
837
+ arg => arg . name ,
838
+ arg => ( {
839
+ type : arg . type ,
840
+ defaultValue : arg . defaultValue ,
841
+ description : arg . description ,
842
+ astNode : arg . astNode ,
843
+ } ) ,
844
+ ) ;
845
+ }
846
+
776
847
export type GraphQLObjectTypeConfig < TSource , TContext > = {
777
848
name : string ,
778
849
interfaces ?: Thunk < ?Array < GraphQLInterfaceType >> ,
@@ -783,6 +854,16 @@ export type GraphQLObjectTypeConfig<TSource, TContext> = {
783
854
extensionASTNodes ?: ?$ReadOnlyArray < ObjectTypeExtensionNode > ,
784
855
} ;
785
856
857
+ export type GraphQLObjectTypeExactConfig < TSource , TContext > = { |
858
+ name : string ,
859
+ interfaces : Array < GraphQLInterfaceType > ,
860
+ fields : GraphQLFieldExactConfigMap < TSource , TContext> ,
861
+ isTypeOf : ?GraphQLIsTypeOfFn < TSource , TContext> ,
862
+ description : ?string ,
863
+ astNode ?: ?ObjectTypeDefinitionNode ,
864
+ extensionASTNodes : $ReadOnlyArray < ObjectTypeExtensionNode > ,
865
+ | } ;
866
+
786
867
export type GraphQLTypeResolver < TSource , TContext > = (
787
868
value : TSource ,
788
869
context : TContext ,
@@ -838,7 +919,24 @@ export type GraphQLFieldConfig<
838
919
astNode ?: ?FieldDefinitionNode ,
839
920
} ;
840
921
922
+ export type GraphQLFieldExactConfig <
923
+ TSource ,
924
+ TContext ,
925
+ TArgs = { [ argument : string ] : any } ,
926
+ > = { |
927
+ type : GraphQLOutputType ,
928
+ args : GraphQLFieldExactConfigArgumentMap ,
929
+ resolve : ?GraphQLFieldResolver < TSource , TContext, TArgs> ,
930
+ subscribe : ?GraphQLFieldResolver < TSource , TContext, TArgs> ,
931
+ deprecationReason : ?string ,
932
+ description : ?string ,
933
+ astNode : ?FieldDefinitionNode ,
934
+ | } ;
935
+
841
936
export type GraphQLFieldConfigArgumentMap = ObjMap < GraphQLArgumentConfig > ;
937
+ export type GraphQLFieldExactConfigArgumentMap = ObjMap <
938
+ GraphQLArgumentExactConfig ,
939
+ > ;
842
940
843
941
export type GraphQLArgumentConfig = {
844
942
type : GraphQLInputType ,
@@ -847,9 +945,19 @@ export type GraphQLArgumentConfig = {
847
945
astNode ?: ?InputValueDefinitionNode ,
848
946
} ;
849
947
948
+ export type GraphQLArgumentExactConfig = { |
949
+ type : GraphQLInputType ,
950
+ defaultValue : mixed ,
951
+ description : ?string ,
952
+ astNode : ?InputValueDefinitionNode ,
953
+ | } ;
954
+
850
955
export type GraphQLFieldConfigMap < TSource , TContext > = ObjMap <
851
956
GraphQLFieldConfig < TSource , TContext > ,
852
957
> ;
958
+ export type GraphQLFieldExactConfigMap < TSource , TContext > = ObjMap <
959
+ GraphQLFieldExactConfig < TSource , TContext > ,
960
+ > ;
853
961
854
962
export type GraphQLField <
855
963
TSource ,
@@ -930,6 +1038,17 @@ export class GraphQLInterfaceType {
930
1038
) ;
931
1039
}
932
1040
1041
+ toConfig ( ) : GraphQLInterfaceTypeExactConfig < * , * > {
1042
+ return {
1043
+ name : this . name ,
1044
+ fields : fieldsToFieldsConfig ( this . getFields ( ) ) ,
1045
+ resolveType : this . resolveType ,
1046
+ description : this . description ,
1047
+ astNode : this . astNode ,
1048
+ extensionASTNodes : this . extensionASTNodes || [ ] ,
1049
+ } ;
1050
+ }
1051
+
933
1052
toString ( ) : string {
934
1053
return this . name ;
935
1054
}
@@ -956,6 +1075,15 @@ export type GraphQLInterfaceTypeConfig<TSource, TContext> = {
956
1075
extensionASTNodes ?: ?$ReadOnlyArray < InterfaceTypeExtensionNode > ,
957
1076
} ;
958
1077
1078
+ export type GraphQLInterfaceTypeExactConfig < TSource , TContext > = { |
1079
+ name : string ,
1080
+ fields : GraphQLFieldExactConfigMap < TSource , TContext> ,
1081
+ resolveType : ?GraphQLTypeResolver < TSource , TContext> ,
1082
+ description : ?string ,
1083
+ astNode : ?InterfaceTypeDefinitionNode ,
1084
+ extensionASTNodes : $ReadOnlyArray < InterfaceTypeExtensionNode > ,
1085
+ | } ;
1086
+
959
1087
/**
960
1088
* Union Type Definition
961
1089
*
@@ -1009,6 +1137,16 @@ export class GraphQLUnionType {
1009
1137
) ;
1010
1138
}
1011
1139
1140
+ toConfig ( ) : GraphQLUnionTypeExactConfig < * , * > {
1141
+ return {
1142
+ name : this . name ,
1143
+ types : this . getTypes ( ) ,
1144
+ resolveType : this . resolveType ,
1145
+ description : this . description ,
1146
+ astNode : this . astNode ,
1147
+ } ;
1148
+ }
1149
+
1012
1150
toString ( ) : string {
1013
1151
return this . name ;
1014
1152
}
@@ -1047,6 +1185,14 @@ export type GraphQLUnionTypeConfig<TSource, TContext> = {
1047
1185
astNode ?: ?UnionTypeDefinitionNode ,
1048
1186
} ;
1049
1187
1188
+ export type GraphQLUnionTypeExactConfig < TSource , TContext > = {
1189
+ name : string ,
1190
+ types : Array < GraphQLObjectType > ,
1191
+ resolveType : ?GraphQLTypeResolver < TSource , TContext> ,
1192
+ description : ?string ,
1193
+ astNode : ?UnionTypeDefinitionNode ,
1194
+ } ;
1195
+
1050
1196
/**
1051
1197
* Enum Type Definition
1052
1198
*
@@ -1124,6 +1270,24 @@ export class GraphQLEnumType /* <T> */ {
1124
1270
}
1125
1271
}
1126
1272
1273
+ toConfig ( ) : GraphQLEnumTypeConfig {
1274
+ return {
1275
+ name : this . name ,
1276
+ values : keyValMap (
1277
+ this . getValues ( ) ,
1278
+ value => value . name ,
1279
+ value => ( {
1280
+ value : value . value ,
1281
+ deprecationReason : value . deprecationReason ,
1282
+ description : value . description ,
1283
+ astNode : value . astNode ,
1284
+ } ) ,
1285
+ ) ,
1286
+ description : this . description ,
1287
+ astNode : this . astNode ,
1288
+ } ;
1289
+ }
1290
+
1127
1291
toString ( ) : string {
1128
1292
return this . name ;
1129
1293
}
@@ -1174,17 +1338,35 @@ export type GraphQLEnumTypeConfig /* <T> */ = {
1174
1338
astNode ?: ?EnumTypeDefinitionNode ,
1175
1339
} ;
1176
1340
1341
+ export type GraphQLEnumTypeExactConfig /* <T> */ = { |
1342
+ name : string ,
1343
+ values : GraphQLEnumValueExactConfigMap /* <T> */ ,
1344
+ description : ?string ,
1345
+ astNode : ?EnumTypeDefinitionNode ,
1346
+ | } ;
1347
+
1177
1348
export type GraphQLEnumValueConfigMap /* <T> */ = ObjMap <
1178
1349
GraphQLEnumValueConfig /* <T> */ ,
1179
1350
> ;
1180
1351
1352
+ export type GraphQLEnumValueExactConfigMap /* <T> */ = ObjMap <
1353
+ GraphQLEnumValueExactConfig /* <T> */ ,
1354
+ > ;
1355
+
1181
1356
export type GraphQLEnumValueConfig /* <T> */ = {
1182
1357
value ?: any /* T */ ,
1183
1358
deprecationReason ?: ?string ,
1184
1359
description ?: ?string ,
1185
1360
astNode ?: ?EnumValueDefinitionNode ,
1186
1361
} ;
1187
1362
1363
+ export type GraphQLEnumValueExactConfig /* <T> */ = { |
1364
+ value ?: any /* T */ ,
1365
+ deprecationReason : ?string ,
1366
+ description : ?string ,
1367
+ astNode : ?EnumValueDefinitionNode ,
1368
+ | } ;
1369
+
1188
1370
export type GraphQLEnumValue /* < T > */ = {
1189
1371
name : string ,
1190
1372
description : ?string ,
@@ -1257,6 +1439,24 @@ export class GraphQLInputObjectType {
1257
1439
return resultFieldMap ;
1258
1440
}
1259
1441
1442
+ toConfig ( ) : GraphQLInputObjectTypeExactConfig {
1443
+ return {
1444
+ name : this . name ,
1445
+ fields : keyValMap (
1446
+ objectValues ( this . getFields ( ) ) ,
1447
+ field => field . name ,
1448
+ field => ( {
1449
+ type : field . type ,
1450
+ defaultValue : field . defaultValue ,
1451
+ description : field . description ,
1452
+ astNode : field . astNode ,
1453
+ } ) ,
1454
+ ) ,
1455
+ description : this . description ,
1456
+ astNode : this . astNode ,
1457
+ } ;
1458
+ }
1459
+
1260
1460
toString ( ) : string {
1261
1461
return this . name ;
1262
1462
}
@@ -1277,15 +1477,30 @@ export type GraphQLInputObjectTypeConfig = {
1277
1477
description ?: ?string ,
1278
1478
astNode ?: ?InputObjectTypeDefinitionNode ,
1279
1479
} ;
1480
+ export type GraphQLInputObjectTypeExactConfig = { |
1481
+ name : string ,
1482
+ fields : GraphQLInputFieldExactConfigMap ,
1483
+ description : ?string ,
1484
+ astNode : ?InputObjectTypeDefinitionNode ,
1485
+ | } ;
1280
1486
1281
1487
export type GraphQLInputFieldConfig = {
1282
1488
type : GraphQLInputType ,
1283
1489
defaultValue ?: mixed ,
1284
1490
description ?: ?string ,
1285
1491
astNode ?: ?InputValueDefinitionNode ,
1286
1492
} ;
1493
+ export type GraphQLInputFieldExactConfig = { |
1494
+ type : GraphQLInputType ,
1495
+ defaultValue : mixed ,
1496
+ description : ?string ,
1497
+ astNode : ?InputValueDefinitionNode ,
1498
+ | } ;
1287
1499
1288
1500
export type GraphQLInputFieldConfigMap = ObjMap < GraphQLInputFieldConfig > ;
1501
+ export type GraphQLInputFieldExactConfigMap = ObjMap <
1502
+ GraphQLInputFieldExactConfig ,
1503
+ > ;
1289
1504
1290
1505
export type GraphQLInputField = {
1291
1506
name : string ,
0 commit comments