From 998bea680d6e11e1c055a400a887a9539de08f75 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Tue, 15 Dec 2020 09:13:49 +0200 Subject: [PATCH] Extract types for normalized configs into named types (#2868) --- src/type/definition.js | 90 ++++++++++++++++++++++++------------------ src/type/directives.js | 14 ++++--- 2 files changed, 59 insertions(+), 45 deletions(-) diff --git a/src/type/definition.js b/src/type/definition.js index ca0e1f5a38..aebb4e2417 100644 --- a/src/type/definition.js +++ b/src/type/definition.js @@ -620,14 +620,7 @@ export class GraphQLScalarType { } } - toConfig(): {| - ...GraphQLScalarTypeConfig, - serialize: GraphQLScalarSerializer, - parseValue: GraphQLScalarValueParser, - parseLiteral: GraphQLScalarLiteralParser, - extensions: ?ReadOnlyObjMap, - extensionASTNodes: $ReadOnlyArray, - |} { + toConfig(): GraphQLScalarTypeNormalizedConfig { return { name: this.name, description: this.description, @@ -686,6 +679,15 @@ export type GraphQLScalarTypeConfig = {| extensionASTNodes?: ?$ReadOnlyArray, |}; +type GraphQLScalarTypeNormalizedConfig = {| + ...GraphQLScalarTypeConfig, + serialize: GraphQLScalarSerializer, + parseValue: GraphQLScalarValueParser, + parseLiteral: GraphQLScalarLiteralParser, + extensions: ?ReadOnlyObjMap, + extensionASTNodes: $ReadOnlyArray, +|}; + /** * Object Type Definition * @@ -766,13 +768,7 @@ export class GraphQLObjectType { return this._interfaces; } - toConfig(): {| - ...GraphQLObjectTypeConfig, - interfaces: Array, - fields: GraphQLFieldConfigMap, - extensions: ?ReadOnlyObjMap, - extensionASTNodes: $ReadOnlyArray, - |} { + toConfig(): GraphQLObjectTypeNormalizedConfig { return { name: this.name, description: this.description, @@ -924,6 +920,14 @@ export type GraphQLObjectTypeConfig = {| extensionASTNodes?: ?$ReadOnlyArray, |}; +type GraphQLObjectTypeNormalizedConfig = {| + ...GraphQLObjectTypeConfig, + interfaces: Array, + fields: GraphQLFieldConfigMap, + extensions: ?ReadOnlyObjMap, + extensionASTNodes: $ReadOnlyArray, +|}; + /** * Note: returning GraphQLObjectType is deprecated and will be removed in v16.0.0 */ @@ -1092,13 +1096,7 @@ export class GraphQLInterfaceType { return this._interfaces; } - toConfig(): {| - ...GraphQLInterfaceTypeConfig, - interfaces: Array, - fields: GraphQLFieldConfigMap, - extensions: ?ReadOnlyObjMap, - extensionASTNodes: $ReadOnlyArray, - |} { + toConfig(): GraphQLInterfaceTypeNormalizedConfig { return { name: this.name, description: this.description, @@ -1144,6 +1142,14 @@ export type GraphQLInterfaceTypeConfig = {| extensionASTNodes?: ?$ReadOnlyArray, |}; +export type GraphQLInterfaceTypeNormalizedConfig = {| + ...GraphQLInterfaceTypeConfig, + interfaces: Array, + fields: GraphQLFieldConfigMap, + extensions: ?ReadOnlyObjMap, + extensionASTNodes: $ReadOnlyArray, +|}; + /** * Union Type Definition * @@ -1201,12 +1207,7 @@ export class GraphQLUnionType { return this._types; } - toConfig(): {| - ...GraphQLUnionTypeConfig, - types: Array, - extensions: ?ReadOnlyObjMap, - extensionASTNodes: $ReadOnlyArray, - |} { + toConfig(): GraphQLUnionTypeNormalizedConfig { return { name: this.name, description: this.description, @@ -1261,6 +1262,13 @@ export type GraphQLUnionTypeConfig = {| extensionASTNodes?: ?$ReadOnlyArray, |}; +type GraphQLUnionTypeNormalizedConfig = {| + ...GraphQLUnionTypeConfig, + types: Array, + extensions: ?ReadOnlyObjMap, + extensionASTNodes: $ReadOnlyArray, +|}; + /** * Enum Type Definition * @@ -1369,11 +1377,7 @@ export class GraphQLEnumType /* */ { return enumValue.value; } - toConfig(): {| - ...GraphQLEnumTypeConfig, - extensions: ?ReadOnlyObjMap, - extensionASTNodes: $ReadOnlyArray, - |} { + toConfig(): GraphQLEnumTypeNormalizedConfig { const values = keyValMap( this.getValues(), (value) => value.name, @@ -1462,6 +1466,12 @@ export type GraphQLEnumTypeConfig /* */ = {| extensionASTNodes?: ?$ReadOnlyArray, |}; +type GraphQLEnumTypeNormalizedConfig = {| + ...GraphQLEnumTypeConfig, + extensions: ?ReadOnlyObjMap, + extensionASTNodes: $ReadOnlyArray, +|}; + export type GraphQLEnumValueConfigMap /* */ = ObjMap */>; export type GraphQLEnumValueConfig /* */ = {| @@ -1531,12 +1541,7 @@ export class GraphQLInputObjectType { return this._fields; } - toConfig(): {| - ...GraphQLInputObjectTypeConfig, - fields: GraphQLInputFieldConfigMap, - extensions: ?ReadOnlyObjMap, - extensionASTNodes: $ReadOnlyArray, - |} { + toConfig(): GraphQLInputObjectTypeNormalizedConfig { const fields = mapValue(this.getFields(), (field) => ({ description: field.description, type: field.type, @@ -1607,6 +1612,13 @@ export type GraphQLInputObjectTypeConfig = {| extensionASTNodes?: ?$ReadOnlyArray, |}; +type GraphQLInputObjectTypeNormalizedConfig = {| + ...GraphQLInputObjectTypeConfig, + fields: GraphQLInputFieldConfigMap, + extensions: ?ReadOnlyObjMap, + extensionASTNodes: $ReadOnlyArray, +|}; + export type GraphQLInputFieldConfig = {| description?: ?string, type: GraphQLInputType, diff --git a/src/type/directives.js b/src/type/directives.js index ff4cce6dd2..21a8055dbd 100644 --- a/src/type/directives.js +++ b/src/type/directives.js @@ -84,12 +84,7 @@ export class GraphQLDirective { })); } - toConfig(): {| - ...GraphQLDirectiveConfig, - args: GraphQLFieldConfigArgumentMap, - isRepeatable: boolean, - extensions: ?ReadOnlyObjMap, - |} { + toConfig(): GraphQLDirectiveNormalizedConfig { return { name: this.name, description: this.description, @@ -128,6 +123,13 @@ export type GraphQLDirectiveConfig = {| astNode?: ?DirectiveDefinitionNode, |}; +type GraphQLDirectiveNormalizedConfig = {| + ...GraphQLDirectiveConfig, + args: GraphQLFieldConfigArgumentMap, + isRepeatable: boolean, + extensions: ?ReadOnlyObjMap, +|}; + /** * Used to conditionally include fields or fragments. */