@@ -13,6 +13,8 @@ import instanceOf from '../jsutils/instanceOf';
13
13
import inspect from '../jsutils/inspect' ;
14
14
import invariant from '../jsutils/invariant' ;
15
15
import keyMap from '../jsutils/keyMap' ;
16
+ import keyValMap from '../jsutils/keyValMap' ;
17
+ import objectValues from '../jsutils/objectValues' ;
16
18
import type { ObjMap } from '../jsutils/ObjMap' ;
17
19
import objectEntries from '../jsutils/objectEntries' ;
18
20
import { Kind } from '../language/kinds' ;
@@ -567,6 +569,18 @@ export class GraphQLScalarType {
567
569
}
568
570
}
569
571
572
+ toConfig ( ) : GraphQLScalarTypeExactConfig < * , * > {
573
+ return {
574
+ name : this . name ,
575
+ description : this . description ,
576
+ serialize : this . serialize ,
577
+ parseValue : this . parseValue ,
578
+ parseLiteral : this . parseLiteral ,
579
+ astNode : this . astNode ,
580
+ extensionASTNodes : this . extensionASTNodes || [ ] ,
581
+ } ;
582
+ }
583
+
570
584
toString ( ) : string {
571
585
return this . name ;
572
586
}
@@ -596,6 +610,19 @@ export type GraphQLScalarTypeConfig<TInternal, TExternal> = {|
596
610
extensionASTNodes ?: ?$ReadOnlyArray < ScalarTypeExtensionNode > ,
597
611
| } ;
598
612
613
+ export type GraphQLScalarTypeExactConfig < TInternal , TExternal > = { |
614
+ name : string ,
615
+ description : ?string ,
616
+ // Serializes an internal value to include in a response.
617
+ serialize : GraphQLScalarSerializer < TExternal > ,
618
+ // Parses an externally provided value to use as an input.
619
+ parseValue : GraphQLScalarValueParser < TInternal > ,
620
+ // Parses an externally provided literal value to use as an input.
621
+ parseLiteral : GraphQLScalarLiteralParser < TInternal > ,
622
+ astNode : ?ScalarTypeDefinitionNode ,
623
+ extensionASTNodes : $ReadOnlyArray < ScalarTypeExtensionNode > ,
624
+ | } ;
625
+
599
626
/**
600
627
* Object Type Definition
601
628
*
@@ -673,6 +700,18 @@ export class GraphQLObjectType {
673
700
return this . _interfaces ;
674
701
}
675
702
703
+ toConfig ( ) : GraphQLObjectTypeExactConfig < * , * > {
704
+ return {
705
+ name : this . name ,
706
+ interfaces : this . getInterfaces ( ) ,
707
+ fields : fieldsToFieldsConfig ( this . getFields ( ) ) ,
708
+ isTypeOf : this . isTypeOf ,
709
+ description : this . description ,
710
+ astNode : this . astNode ,
711
+ extensionASTNodes : this . extensionASTNodes || [ ] ,
712
+ } ;
713
+ }
714
+
676
715
toString ( ) : string {
677
716
return this . name ;
678
717
}
@@ -751,6 +790,39 @@ function isPlainObj(obj) {
751
790
return obj && typeof obj === 'object' && !Array.isArray(obj);
752
791
}
753
792
793
+ function fieldsToFieldsConfig<TSource, TContext>(
794
+ fields: GraphQLFieldMap<TSource, TContext>,
795
+ ): GraphQLFieldExactConfigMap<TSource, TContext> {
796
+ return keyValMap(
797
+ objectValues(fields),
798
+ field => field.name,
799
+ field => ({
800
+ type: field.type,
801
+ args: argsToArgsConfig(field.args),
802
+ resolve: field.resolve,
803
+ subscribe: field.subscribe,
804
+ deprecationReason: field.deprecationReason,
805
+ description: field.description,
806
+ astNode: field.astNode,
807
+ }),
808
+ );
809
+ }
810
+
811
+ export function argsToArgsConfig(
812
+ args: Array<GraphQLArgument>,
813
+ ): GraphQLFieldExactConfigArgumentMap {
814
+ return keyValMap(
815
+ args,
816
+ arg => arg.name,
817
+ arg => ({
818
+ type: arg.type,
819
+ defaultValue: arg.defaultValue,
820
+ description: arg.description,
821
+ astNode: arg.astNode,
822
+ }),
823
+ );
824
+ }
825
+
754
826
export type GraphQLObjectTypeConfig<TSource, TContext> = {|
755
827
name: string,
756
828
interfaces?: Thunk<?Array<GraphQLInterfaceType>>,
@@ -761,6 +833,16 @@ export type GraphQLObjectTypeConfig<TSource, TContext> = {|
761
833
extensionASTNodes?: ?$ReadOnlyArray<ObjectTypeExtensionNode>,
762
834
|};
763
835
836
+ export type GraphQLObjectTypeExactConfig<TSource, TContext> = {|
837
+ name: string,
838
+ interfaces: Array<GraphQLInterfaceType>,
839
+ fields: GraphQLFieldExactConfigMap<TSource, TContext>,
840
+ isTypeOf: ?GraphQLIsTypeOfFn<TSource, TContext>,
841
+ description: ?string,
842
+ astNode: ?ObjectTypeDefinitionNode,
843
+ extensionASTNodes: $ReadOnlyArray<ObjectTypeExtensionNode>,
844
+ |};
845
+
764
846
export type GraphQLTypeResolver<TSource, TContext> = (
765
847
value: TSource,
766
848
context: TContext,
@@ -816,7 +898,22 @@ export type GraphQLFieldConfig<
816
898
astNode?: ?FieldDefinitionNode,
817
899
|};
818
900
901
+ export type GraphQLFieldExactConfig<
902
+ TSource,
903
+ TContext,
904
+ TArgs = { [argument: string]: any },
905
+ > = {|
906
+ type: GraphQLOutputType,
907
+ args: GraphQLFieldExactConfigArgumentMap,
908
+ resolve: ?GraphQLFieldResolver<TSource, TContext, TArgs>,
909
+ subscribe: ?GraphQLFieldResolver<TSource, TContext, TArgs>,
910
+ deprecationReason: ?string,
911
+ description: ?string,
912
+ astNode: ?FieldDefinitionNode,
913
+ |};
914
+
819
915
export type GraphQLFieldConfigArgumentMap = ObjMap<GraphQLArgumentConfig>;
916
+ export type GraphQLFieldExactConfigArgumentMap = ObjMap<GraphQLArgumentExactConfig>;
820
917
821
918
export type GraphQLArgumentConfig = {|
822
919
type: GraphQLInputType,
@@ -825,9 +922,19 @@ export type GraphQLArgumentConfig = {|
825
922
astNode?: ?InputValueDefinitionNode,
826
923
|};
827
924
925
+ export type GraphQLArgumentExactConfig = {|
926
+ type: GraphQLInputType,
927
+ defaultValue: mixed,
928
+ description: ?string,
929
+ astNode: ?InputValueDefinitionNode,
930
+ |};
931
+
828
932
export type GraphQLFieldConfigMap<TSource, TContext> = ObjMap<
829
933
GraphQLFieldConfig<TSource, TContext>,
830
934
>;
935
+ export type GraphQLFieldExactConfigMap<TSource, TContext> = ObjMap<
936
+ GraphQLFieldExactConfig<TSource, TContext>,
937
+ >;
831
938
832
939
export type GraphQLField<
833
940
TSource,
@@ -910,6 +1017,17 @@ export class GraphQLInterfaceType {
910
1017
return this._fields;
911
1018
}
912
1019
1020
+ toConfig(): GraphQLInterfaceTypeExactConfig<*, *> {
1021
+ return {
1022
+ name: this.name,
1023
+ fields: fieldsToFieldsConfig(this.getFields()),
1024
+ resolveType: this.resolveType,
1025
+ description: this.description,
1026
+ astNode: this.astNode,
1027
+ extensionASTNodes: this.extensionASTNodes || [],
1028
+ };
1029
+ }
1030
+
913
1031
toString(): string {
914
1032
return this.name;
915
1033
}
@@ -933,6 +1051,15 @@ export type GraphQLInterfaceTypeConfig<TSource, TContext> = {|
933
1051
extensionASTNodes?: ?$ReadOnlyArray<InterfaceTypeExtensionNode>,
934
1052
|};
935
1053
1054
+ export type GraphQLInterfaceTypeExactConfig<TSource, TContext> = {|
1055
+ name: string,
1056
+ fields: GraphQLFieldExactConfigMap<TSource, TContext>,
1057
+ resolveType: ?GraphQLTypeResolver<TSource, TContext>,
1058
+ description: ?string,
1059
+ astNode: ?InterfaceTypeDefinitionNode,
1060
+ extensionASTNodes: $ReadOnlyArray<InterfaceTypeExtensionNode>,
1061
+ |};
1062
+
936
1063
/**
937
1064
* Union Type Definition
938
1065
*
@@ -987,6 +1114,17 @@ export class GraphQLUnionType {
987
1114
return this._types;
988
1115
}
989
1116
1117
+ toConfig(): GraphQLUnionTypeExactConfig<*, *> {
1118
+ return {
1119
+ name: this.name,
1120
+ types: this.getTypes(),
1121
+ resolveType: this.resolveType,
1122
+ description: this.description,
1123
+ astNode: this.astNode,
1124
+ extensionASTNodes: this.extensionASTNodes || [],
1125
+ };
1126
+ }
1127
+
990
1128
toString(): string {
991
1129
return this.name;
992
1130
}
@@ -1022,6 +1160,15 @@ export type GraphQLUnionTypeConfig<TSource, TContext> = {|
1022
1160
extensionASTNodes?: ?$ReadOnlyArray<UnionTypeExtensionNode>,
1023
1161
|};
1024
1162
1163
+ export type GraphQLUnionTypeExactConfig<TSource, TContext> = {
1164
+ name: string,
1165
+ types: Array<GraphQLObjectType>,
1166
+ resolveType: ?GraphQLTypeResolver<TSource, TContext>,
1167
+ description: ?string,
1168
+ astNode: ?UnionTypeDefinitionNode,
1169
+ extensionASTNodes: $ReadOnlyArray<UnionTypeExtensionNode>,
1170
+ };
1171
+
1025
1172
/**
1026
1173
* Enum Type Definition
1027
1174
*
@@ -1101,6 +1248,25 @@ export class GraphQLEnumType /* <T> */ {
1101
1248
}
1102
1249
}
1103
1250
1251
+ toConfig(): GraphQLEnumTypeExactConfig {
1252
+ return {
1253
+ name: this.name,
1254
+ values: keyValMap(
1255
+ this.getValues(),
1256
+ value => value.name,
1257
+ value => ({
1258
+ value: value.value,
1259
+ deprecationReason: value.deprecationReason,
1260
+ description: value.description,
1261
+ astNode: value.astNode,
1262
+ }),
1263
+ ),
1264
+ description: this.description,
1265
+ astNode: this.astNode,
1266
+ extensionASTNodes: this.extensionASTNodes || [],
1267
+ };
1268
+ }
1269
+
1104
1270
toString(): string {
1105
1271
return this.name;
1106
1272
}
@@ -1148,15 +1314,32 @@ export type GraphQLEnumTypeConfig /* <T> */ = {|
1148
1314
extensionASTNodes?: ?$ReadOnlyArray<EnumTypeExtensionNode>,
1149
1315
|};
1150
1316
1317
+ export type GraphQLEnumTypeExactConfig /* <T> */ = {|
1318
+ name: string,
1319
+ values: GraphQLEnumValueExactConfigMap /* <T> */,
1320
+ description: ?string,
1321
+ astNode: ?EnumTypeDefinitionNode,
1322
+ extensionASTNodes: $ReadOnlyArray<EnumTypeExtensionNode>,
1323
+ |};
1324
+
1151
1325
export type GraphQLEnumValueConfigMap /* <T> */ = ObjMap<GraphQLEnumValueConfig /* <T> */>;
1152
1326
1327
+ export type GraphQLEnumValueExactConfigMap /* <T> */ = ObjMap<GraphQLEnumValueExactConfig /* <T> */>;
1328
+
1153
1329
export type GraphQLEnumValueConfig /* <T> */ = {|
1154
1330
value?: any /* T */,
1155
1331
deprecationReason?: ?string,
1156
1332
description?: ?string,
1157
1333
astNode?: ?EnumValueDefinitionNode,
1158
1334
|};
1159
1335
1336
+ export type GraphQLEnumValueExactConfig /* <T> */ = {|
1337
+ value?: any /* T */,
1338
+ deprecationReason: ?string,
1339
+ description: ?string,
1340
+ astNode: ?EnumValueDefinitionNode,
1341
+ |};
1342
+
1160
1343
export type GraphQLEnumValue /* <T> */ = {
1161
1344
name: string,
1162
1345
description: ?string,
@@ -1210,6 +1393,25 @@ export class GraphQLInputObjectType {
1210
1393
return this._fields;
1211
1394
}
1212
1395
1396
+ toConfig(): GraphQLInputObjectTypeExactConfig {
1397
+ return {
1398
+ name: this.name,
1399
+ fields: keyValMap(
1400
+ objectValues(this.getFields()),
1401
+ field => field.name,
1402
+ field => ({
1403
+ type: field.type,
1404
+ defaultValue: field.defaultValue,
1405
+ description: field.description,
1406
+ astNode: field.astNode,
1407
+ }),
1408
+ ),
1409
+ description: this.description,
1410
+ astNode: this.astNode,
1411
+ extensionASTNodes: this.extensionASTNodes || [],
1412
+ };
1413
+ }
1414
+
1213
1415
toString(): string {
1214
1416
return this.name;
1215
1417
}
@@ -1252,14 +1454,30 @@ export type GraphQLInputObjectTypeConfig = {|
1252
1454
extensionASTNodes ?: ?$ReadOnlyArray < InputObjectTypeExtensionNode > ,
1253
1455
| } ;
1254
1456
1457
+ export type GraphQLInputObjectTypeExactConfig = { |
1458
+ name : string ,
1459
+ fields : GraphQLInputFieldExactConfigMap ,
1460
+ description : ?string ,
1461
+ astNode : ?InputObjectTypeDefinitionNode ,
1462
+ extensionASTNodes : $ReadOnlyArray < InputObjectTypeExtensionNode > ,
1463
+ | } ;
1464
+
1255
1465
export type GraphQLInputFieldConfig = { |
1256
1466
type : GraphQLInputType ,
1257
1467
defaultValue ?: mixed ,
1258
1468
description ?: ?string ,
1259
1469
astNode ?: ?InputValueDefinitionNode ,
1260
1470
| } ;
1261
1471
1472
+ export type GraphQLInputFieldExactConfig = { |
1473
+ type : GraphQLInputType ,
1474
+ defaultValue : mixed ,
1475
+ description : ?string ,
1476
+ astNode : ?InputValueDefinitionNode ,
1477
+ | } ;
1478
+
1262
1479
export type GraphQLInputFieldConfigMap = ObjMap < GraphQLInputFieldConfig > ;
1480
+ export type GraphQLInputFieldExactConfigMap = ObjMap < GraphQLInputFieldExactConfig > ;
1263
1481
1264
1482
export type GraphQLInputField = {
1265
1483
name : string ,
0 commit comments