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