Skip to content

Commit

Permalink
Extract types for normalized configs into named types (#2868)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Dec 15, 2020
1 parent cd273ad commit 998bea6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 45 deletions.
90 changes: 51 additions & 39 deletions src/type/definition.js
Expand Up @@ -620,14 +620,7 @@ export class GraphQLScalarType {
}
}

toConfig(): {|
...GraphQLScalarTypeConfig<mixed, mixed>,
serialize: GraphQLScalarSerializer<mixed>,
parseValue: GraphQLScalarValueParser<mixed>,
parseLiteral: GraphQLScalarLiteralParser<mixed>,
extensions: ?ReadOnlyObjMap<mixed>,
extensionASTNodes: $ReadOnlyArray<ScalarTypeExtensionNode>,
|} {
toConfig(): GraphQLScalarTypeNormalizedConfig {
return {
name: this.name,
description: this.description,
Expand Down Expand Up @@ -686,6 +679,15 @@ export type GraphQLScalarTypeConfig<TInternal, TExternal> = {|
extensionASTNodes?: ?$ReadOnlyArray<ScalarTypeExtensionNode>,
|};

type GraphQLScalarTypeNormalizedConfig = {|
...GraphQLScalarTypeConfig<mixed, mixed>,
serialize: GraphQLScalarSerializer<mixed>,
parseValue: GraphQLScalarValueParser<mixed>,
parseLiteral: GraphQLScalarLiteralParser<mixed>,
extensions: ?ReadOnlyObjMap<mixed>,
extensionASTNodes: $ReadOnlyArray<ScalarTypeExtensionNode>,
|};

/**
* Object Type Definition
*
Expand Down Expand Up @@ -766,13 +768,7 @@ export class GraphQLObjectType {
return this._interfaces;
}

toConfig(): {|
...GraphQLObjectTypeConfig<any, any>,
interfaces: Array<GraphQLInterfaceType>,
fields: GraphQLFieldConfigMap<any, any>,
extensions: ?ReadOnlyObjMap<mixed>,
extensionASTNodes: $ReadOnlyArray<ObjectTypeExtensionNode>,
|} {
toConfig(): GraphQLObjectTypeNormalizedConfig {
return {
name: this.name,
description: this.description,
Expand Down Expand Up @@ -924,6 +920,14 @@ export type GraphQLObjectTypeConfig<TSource, TContext> = {|
extensionASTNodes?: ?$ReadOnlyArray<ObjectTypeExtensionNode>,
|};

type GraphQLObjectTypeNormalizedConfig = {|
...GraphQLObjectTypeConfig<any, any>,
interfaces: Array<GraphQLInterfaceType>,
fields: GraphQLFieldConfigMap<any, any>,
extensions: ?ReadOnlyObjMap<mixed>,
extensionASTNodes: $ReadOnlyArray<ObjectTypeExtensionNode>,
|};

/**
* Note: returning GraphQLObjectType is deprecated and will be removed in v16.0.0
*/
Expand Down Expand Up @@ -1092,13 +1096,7 @@ export class GraphQLInterfaceType {
return this._interfaces;
}

toConfig(): {|
...GraphQLInterfaceTypeConfig<any, any>,
interfaces: Array<GraphQLInterfaceType>,
fields: GraphQLFieldConfigMap<any, any>,
extensions: ?ReadOnlyObjMap<mixed>,
extensionASTNodes: $ReadOnlyArray<InterfaceTypeExtensionNode>,
|} {
toConfig(): GraphQLInterfaceTypeNormalizedConfig {
return {
name: this.name,
description: this.description,
Expand Down Expand Up @@ -1144,6 +1142,14 @@ export type GraphQLInterfaceTypeConfig<TSource, TContext> = {|
extensionASTNodes?: ?$ReadOnlyArray<InterfaceTypeExtensionNode>,
|};

export type GraphQLInterfaceTypeNormalizedConfig = {|
...GraphQLInterfaceTypeConfig<any, any>,
interfaces: Array<GraphQLInterfaceType>,
fields: GraphQLFieldConfigMap<any, any>,
extensions: ?ReadOnlyObjMap<mixed>,
extensionASTNodes: $ReadOnlyArray<InterfaceTypeExtensionNode>,
|};

/**
* Union Type Definition
*
Expand Down Expand Up @@ -1201,12 +1207,7 @@ export class GraphQLUnionType {
return this._types;
}

toConfig(): {|
...GraphQLUnionTypeConfig<any, any>,
types: Array<GraphQLObjectType>,
extensions: ?ReadOnlyObjMap<mixed>,
extensionASTNodes: $ReadOnlyArray<UnionTypeExtensionNode>,
|} {
toConfig(): GraphQLUnionTypeNormalizedConfig {
return {
name: this.name,
description: this.description,
Expand Down Expand Up @@ -1261,6 +1262,13 @@ export type GraphQLUnionTypeConfig<TSource, TContext> = {|
extensionASTNodes?: ?$ReadOnlyArray<UnionTypeExtensionNode>,
|};

type GraphQLUnionTypeNormalizedConfig = {|
...GraphQLUnionTypeConfig<any, any>,
types: Array<GraphQLObjectType>,
extensions: ?ReadOnlyObjMap<mixed>,
extensionASTNodes: $ReadOnlyArray<UnionTypeExtensionNode>,
|};

/**
* Enum Type Definition
*
Expand Down Expand Up @@ -1369,11 +1377,7 @@ export class GraphQLEnumType /* <T> */ {
return enumValue.value;
}

toConfig(): {|
...GraphQLEnumTypeConfig,
extensions: ?ReadOnlyObjMap<mixed>,
extensionASTNodes: $ReadOnlyArray<EnumTypeExtensionNode>,
|} {
toConfig(): GraphQLEnumTypeNormalizedConfig {
const values = keyValMap(
this.getValues(),
(value) => value.name,
Expand Down Expand Up @@ -1462,6 +1466,12 @@ export type GraphQLEnumTypeConfig /* <T> */ = {|
extensionASTNodes?: ?$ReadOnlyArray<EnumTypeExtensionNode>,
|};

type GraphQLEnumTypeNormalizedConfig = {|
...GraphQLEnumTypeConfig,
extensions: ?ReadOnlyObjMap<mixed>,
extensionASTNodes: $ReadOnlyArray<EnumTypeExtensionNode>,
|};

export type GraphQLEnumValueConfigMap /* <T> */ = ObjMap<GraphQLEnumValueConfig /* <T> */>;

export type GraphQLEnumValueConfig /* <T> */ = {|
Expand Down Expand Up @@ -1531,12 +1541,7 @@ export class GraphQLInputObjectType {
return this._fields;
}

toConfig(): {|
...GraphQLInputObjectTypeConfig,
fields: GraphQLInputFieldConfigMap,
extensions: ?ReadOnlyObjMap<mixed>,
extensionASTNodes: $ReadOnlyArray<InputObjectTypeExtensionNode>,
|} {
toConfig(): GraphQLInputObjectTypeNormalizedConfig {
const fields = mapValue(this.getFields(), (field) => ({
description: field.description,
type: field.type,
Expand Down Expand Up @@ -1607,6 +1612,13 @@ export type GraphQLInputObjectTypeConfig = {|
extensionASTNodes?: ?$ReadOnlyArray<InputObjectTypeExtensionNode>,
|};

type GraphQLInputObjectTypeNormalizedConfig = {|
...GraphQLInputObjectTypeConfig,
fields: GraphQLInputFieldConfigMap,
extensions: ?ReadOnlyObjMap<mixed>,
extensionASTNodes: $ReadOnlyArray<InputObjectTypeExtensionNode>,
|};

export type GraphQLInputFieldConfig = {|
description?: ?string,
type: GraphQLInputType,
Expand Down
14 changes: 8 additions & 6 deletions src/type/directives.js
Expand Up @@ -84,12 +84,7 @@ export class GraphQLDirective {
}));
}

toConfig(): {|
...GraphQLDirectiveConfig,
args: GraphQLFieldConfigArgumentMap,
isRepeatable: boolean,
extensions: ?ReadOnlyObjMap<mixed>,
|} {
toConfig(): GraphQLDirectiveNormalizedConfig {
return {
name: this.name,
description: this.description,
Expand Down Expand Up @@ -128,6 +123,13 @@ export type GraphQLDirectiveConfig = {|
astNode?: ?DirectiveDefinitionNode,
|};

type GraphQLDirectiveNormalizedConfig = {|
...GraphQLDirectiveConfig,
args: GraphQLFieldConfigArgumentMap,
isRepeatable: boolean,
extensions: ?ReadOnlyObjMap<mixed>,
|};

/**
* Used to conditionally include fields or fragments.
*/
Expand Down

0 comments on commit 998bea6

Please sign in to comment.