Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change 'toConfig' to always return 'extensionASTNodes' as array #2430

Merged
merged 1 commit into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/type/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ export class GraphQLScalarType {
parseValue: GraphQLScalarValueParser<mixed>,
parseLiteral: GraphQLScalarLiteralParser<mixed>,
extensions: ?ReadOnlyObjMap<mixed>,
extensionASTNodes: ?$ReadOnlyArray<ScalarTypeExtensionNode>,
extensionASTNodes: $ReadOnlyArray<ScalarTypeExtensionNode>,
|} {
return {
name: this.name,
Expand All @@ -617,7 +617,7 @@ export class GraphQLScalarType {
parseLiteral: this.parseLiteral,
extensions: this.extensions,
astNode: this.astNode,
extensionASTNodes: this.extensionASTNodes,
extensionASTNodes: this.extensionASTNodes ?? [],
};
}

Expand Down Expand Up @@ -745,7 +745,7 @@ export class GraphQLObjectType {
interfaces: Array<GraphQLInterfaceType>,
fields: GraphQLFieldConfigMap<any, any>,
extensions: ?ReadOnlyObjMap<mixed>,
extensionASTNodes: ?$ReadOnlyArray<ObjectTypeExtensionNode>,
extensionASTNodes: $ReadOnlyArray<ObjectTypeExtensionNode>,
|} {
return {
name: this.name,
Expand All @@ -755,7 +755,7 @@ export class GraphQLObjectType {
isTypeOf: this.isTypeOf,
extensions: this.extensions,
astNode: this.astNode,
extensionASTNodes: this.extensionASTNodes,
extensionASTNodes: this.extensionASTNodes || [],
};
}

Expand Down Expand Up @@ -1055,7 +1055,7 @@ export class GraphQLInterfaceType {
interfaces: Array<GraphQLInterfaceType>,
fields: GraphQLFieldConfigMap<any, any>,
extensions: ?ReadOnlyObjMap<mixed>,
extensionASTNodes: ?$ReadOnlyArray<InterfaceTypeExtensionNode>,
extensionASTNodes: $ReadOnlyArray<InterfaceTypeExtensionNode>,
|} {
return {
name: this.name,
Expand All @@ -1065,7 +1065,7 @@ export class GraphQLInterfaceType {
resolveType: this.resolveType,
extensions: this.extensions,
astNode: this.astNode,
extensionASTNodes: this.extensionASTNodes,
extensionASTNodes: this.extensionASTNodes ?? [],
};
}

Expand Down Expand Up @@ -1158,7 +1158,7 @@ export class GraphQLUnionType {
...GraphQLUnionTypeConfig<any, any>,
types: Array<GraphQLObjectType>,
extensions: ?ReadOnlyObjMap<mixed>,
extensionASTNodes: ?$ReadOnlyArray<UnionTypeExtensionNode>,
extensionASTNodes: $ReadOnlyArray<UnionTypeExtensionNode>,
|} {
return {
name: this.name,
Expand All @@ -1167,7 +1167,7 @@ export class GraphQLUnionType {
resolveType: this.resolveType,
extensions: this.extensions,
astNode: this.astNode,
extensionASTNodes: this.extensionASTNodes,
extensionASTNodes: this.extensionASTNodes ?? [],
};
}

Expand Down Expand Up @@ -1320,7 +1320,7 @@ export class GraphQLEnumType /* <T> */ {
toConfig(): {|
...GraphQLEnumTypeConfig,
extensions: ?ReadOnlyObjMap<mixed>,
extensionASTNodes: ?$ReadOnlyArray<EnumTypeExtensionNode>,
extensionASTNodes: $ReadOnlyArray<EnumTypeExtensionNode>,
|} {
const values = keyValMap(
this.getValues(),
Expand All @@ -1340,7 +1340,7 @@ export class GraphQLEnumType /* <T> */ {
values,
extensions: this.extensions,
astNode: this.astNode,
extensionASTNodes: this.extensionASTNodes,
extensionASTNodes: this.extensionASTNodes ?? [],
};
}

Expand Down Expand Up @@ -1476,7 +1476,7 @@ export class GraphQLInputObjectType {
...GraphQLInputObjectTypeConfig,
fields: GraphQLInputFieldConfigMap,
extensions: ?ReadOnlyObjMap<mixed>,
extensionASTNodes: ?$ReadOnlyArray<InputObjectTypeExtensionNode>,
extensionASTNodes: $ReadOnlyArray<InputObjectTypeExtensionNode>,
|} {
const fields = mapValue(this.getFields(), field => ({
description: field.description,
Expand All @@ -1492,7 +1492,7 @@ export class GraphQLInputObjectType {
fields,
extensions: this.extensions,
astNode: this.astNode,
extensionASTNodes: this.extensionASTNodes,
extensionASTNodes: this.extensionASTNodes ?? [],
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/type/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ export class GraphQLSchema {
directives: this.getDirectives().slice(),
extensions: this.extensions,
astNode: this.astNode,
extensionASTNodes: this.extensionASTNodes,
extensionASTNodes: this.extensionASTNodes ?? [],
assumeValid: this.__validationErrors !== undefined,
};
}
Expand Down Expand Up @@ -391,7 +391,7 @@ export type GraphQLSchemaNormalizedConfig = {|
types: Array<GraphQLNamedType>,
directives: Array<GraphQLDirective>,
extensions: ?ReadOnlyObjMap<mixed>,
extensionASTNodes: ?$ReadOnlyArray<SchemaExtensionNode>,
extensionASTNodes: $ReadOnlyArray<SchemaExtensionNode>,
assumeValid: boolean,
|};

Expand Down
48 changes: 7 additions & 41 deletions src/utilities/extendSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,7 @@ export function extendSchemaImpl(
],
extensions: undefined,
astNode: schemaDef ?? schemaConfig.astNode,
extensionASTNodes: concatMaybeArrays(
schemaConfig.extensionASTNodes,
schemaExtensions,
),
extensionASTNodes: schemaConfig.extensionASTNodes.concat(schemaExtensions),
assumeValid: options?.assumeValid ?? false,
};

Expand Down Expand Up @@ -305,10 +302,7 @@ export function extendSchemaImpl(
})),
...buildInputFieldMap(extensions),
}),
extensionASTNodes: concatMaybeArrays(
config.extensionASTNodes,
extensions,
),
extensionASTNodes: config.extensionASTNodes.concat(extensions),
});
}

Expand All @@ -322,10 +316,7 @@ export function extendSchemaImpl(
...config.values,
...buildEnumValueMap(extensions),
},
extensionASTNodes: concatMaybeArrays(
config.extensionASTNodes,
extensions,
),
extensionASTNodes: config.extensionASTNodes.concat(extensions),
});
}

Expand All @@ -335,10 +326,7 @@ export function extendSchemaImpl(

return new GraphQLScalarType({
...config,
extensionASTNodes: concatMaybeArrays(
config.extensionASTNodes,
extensions,
),
extensionASTNodes: config.extensionASTNodes.concat(extensions),
});
}

Expand All @@ -356,10 +344,7 @@ export function extendSchemaImpl(
...mapValue(config.fields, extendField),
...buildFieldMap(extensions),
}),
extensionASTNodes: concatMaybeArrays(
config.extensionASTNodes,
extensions,
),
extensionASTNodes: config.extensionASTNodes.concat(extensions),
});
}

Expand All @@ -379,10 +364,7 @@ export function extendSchemaImpl(
...mapValue(config.fields, extendField),
...buildFieldMap(extensions),
}),
extensionASTNodes: concatMaybeArrays(
config.extensionASTNodes,
extensions,
),
extensionASTNodes: config.extensionASTNodes.concat(extensions),
});
}

Expand All @@ -396,10 +378,7 @@ export function extendSchemaImpl(
...type.getTypes().map(replaceNamedType),
...buildUnionTypes(extensions),
],
extensionASTNodes: concatMaybeArrays(
config.extensionASTNodes,
extensions,
),
extensionASTNodes: config.extensionASTNodes.concat(extensions),
});
}

Expand Down Expand Up @@ -704,19 +683,6 @@ export function extendSchemaImpl(
}
}

function concatMaybeArrays<X>(
maybeArrayA: ?$ReadOnlyArray<X>,
maybeArrayB: ?$ReadOnlyArray<X>,
): ?$ReadOnlyArray<X> {
if (maybeArrayA == null) {
return maybeArrayB;
}
if (maybeArrayB == null) {
return maybeArrayA;
}
return maybeArrayA.concat(maybeArrayB);
}

const stdTypeMap = keyMap(
specifiedScalarTypes.concat(introspectionTypes),
type => type.name,
Expand Down