Skip to content
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 @@ -586,7 +586,7 @@ export class GraphQLScalarType {
parseValue: GraphQLScalarValueParser<*>,
parseLiteral: GraphQLScalarLiteralParser<*>,
extensions: ?ReadOnlyObjMap<mixed>,
extensionASTNodes: $ReadOnlyArray<ScalarTypeExtensionNode>,
extensionASTNodes: ?$ReadOnlyArray<ScalarTypeExtensionNode>,
|} {
return {
name: this.name,
Expand All @@ -596,7 +596,7 @@ export class GraphQLScalarType {
parseLiteral: this.parseLiteral,
extensions: this.extensions,
astNode: this.astNode,
extensionASTNodes: this.extensionASTNodes || [],
extensionASTNodes: this.extensionASTNodes,
};
}

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

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

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

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

Expand Down Expand Up @@ -1379,7 +1379,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 @@ -1395,7 +1395,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 @@ -263,7 +263,7 @@ export class GraphQLSchema {
types: Array<GraphQLNamedType>,
directives: Array<GraphQLDirective>,
extensions: ?ReadOnlyObjMap<mixed>,
extensionASTNodes: $ReadOnlyArray<SchemaExtensionNode>,
extensionASTNodes: ?$ReadOnlyArray<SchemaExtensionNode>,
assumeValid: boolean,
|} {
return {
Expand All @@ -274,7 +274,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
48 changes: 41 additions & 7 deletions src/utilities/extendSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ export function extendSchema(
types: objectValues(typeMap),
directives: getMergedDirectives(),
astNode: schemaDef || schemaConfig.astNode,
extensionASTNodes: schemaConfig.extensionASTNodes.concat(schemaExts),
extensionASTNodes: concatMaybeArrays(
schemaConfig.extensionASTNodes,
schemaExts,
),
});

// Below are functions used for producing this schema that have closed over
Expand Down Expand Up @@ -285,7 +288,10 @@ export function extendSchema(
field => astBuilder.buildInputField(field),
),
}),
extensionASTNodes: config.extensionASTNodes.concat(extensions),
extensionASTNodes: concatMaybeArrays(
config.extensionASTNodes,
extensions,
),
});
}

Expand All @@ -304,7 +310,10 @@ export function extendSchema(
value => astBuilder.buildEnumValue(value),
),
},
extensionASTNodes: config.extensionASTNodes.concat(extensions),
extensionASTNodes: concatMaybeArrays(
config.extensionASTNodes,
extensions,
),
});
}

Expand All @@ -314,7 +323,10 @@ export function extendSchema(

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

Expand All @@ -341,7 +353,10 @@ export function extendSchema(
node => astBuilder.buildField(node),
),
}),
extensionASTNodes: config.extensionASTNodes.concat(extensions),
extensionASTNodes: concatMaybeArrays(
config.extensionASTNodes,
extensions,
),
});
}

Expand All @@ -362,7 +377,10 @@ export function extendSchema(
node => astBuilder.buildField(node),
),
}),
extensionASTNodes: config.extensionASTNodes.concat(extensions),
extensionASTNodes: concatMaybeArrays(
config.extensionASTNodes,
extensions,
),
});
}

Expand All @@ -380,7 +398,10 @@ export function extendSchema(
// validation with validateSchema() will produce more actionable results.
...typeNodes.map(node => (astBuilder.getNamedType(node): any)),
],
extensionASTNodes: config.extensionASTNodes.concat(extensions),
extensionASTNodes: concatMaybeArrays(
config.extensionASTNodes,
extensions,
),
});
}

Expand All @@ -399,3 +420,16 @@ export function extendSchema(
};
}
}

function concatMaybeArrays<X>(
...arrays: $ReadOnlyArray<?$ReadOnlyArray<X>>
): ?$ReadOnlyArray<X> {
// eslint-disable-next-line no-undef-init
let result = undefined;
for (const maybeArray of arrays) {
if (maybeArray) {
result = result === undefined ? maybeArray : result.concat(maybeArray);
}
}
return result;
}