Skip to content

Commit

Permalink
mergeSchema keeps ENUM description and deprecation (#898)
Browse files Browse the repository at this point in the history
* test: add failing test for merging enum description

* test: actually add failing test

* fix: mergeSchema keeps ENUM description and deprecation status

* Update CHANGELOG.md
  • Loading branch information
chollier authored and stubailo committed Jul 31, 2018
1 parent d15ee0a commit 84df7bd
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Update `IResolvers` to use source & context generics and to support all resolver use cases. [#896](https://github.com/apollographql/graphql-tools/pull/896)
* `WrapQuery`'s `wrapper` param can now return a SelectionSet. [PR #902](https://github.com/apollographql/graphql-tools/pull/902) [Issue #901](https://github.com/apollographql/graphql-tools/issues/901)
* Add null to return type of directive visitors in the TypeScript definition.
* Make sure mergeSchemas keeps Enum descriptions and deprecation status. [PR 898](https://github.com/apollographql/graphql-tools/pull/898/)

### v3.0.5

Expand Down
6 changes: 5 additions & 1 deletion src/stitching/schemaRecreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ export function recreateType(
const values = type.getValues();
const newValues = {};
values.forEach(value => {
newValues[value.name] = { value: value.name };
newValues[value.name] = {
value: value.name,
deprecationReason: value.deprecationReason,
description: value.description,
};
});
return new GraphQLEnumType({
name: type.name,
Expand Down
58 changes: 56 additions & 2 deletions src/test/testMergeSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,20 @@ let enumTest = `
A type that uses an Enum.
"""
enum Color {
"""
A vivid color
"""
RED
}
"""
A type that uses an Enum with a numeric constant.
"""
enum NumericEnum {
TEST
"""
A test description
"""
TEST @deprecated(reason: "This is deprecated")
}
schema {
Expand Down Expand Up @@ -222,12 +228,14 @@ if (process.env.GRAPHQL_VERSION === '^0.11') {
enumTest = `
# A type that uses an Enum.
enum Color {
# A vivid color
RED
}
# A type that uses an Enum with a numeric constant.
enum NumericEnum {
TEST
# A test description
TEST @deprecated(reason: "This is deprecated")
}
schema {
Expand Down Expand Up @@ -606,6 +614,20 @@ testCombinations.forEach(async combination => {
query {
color
numericEnum
numericEnumInfo: __type(name: "NumericEnum") {
enumValues(includeDeprecated: true) {
name
description
isDeprecated
deprecationReason
}
}
colorEnumInfo: __type(name: "Color") {
enumValues {
name
description
}
}
}
`,
);
Expand All @@ -616,6 +638,20 @@ testCombinations.forEach(async combination => {
query {
color
numericEnum
numericEnumInfo: __type(name: "NumericEnum") {
enumValues(includeDeprecated: true) {
name
description
isDeprecated
deprecationReason
}
}
colorEnumInfo: __type(name: "Color") {
enumValues {
name
description
}
}
}
`,
);
Expand All @@ -624,6 +660,24 @@ testCombinations.forEach(async combination => {
data: {
color: 'RED',
numericEnum: 'TEST',
numericEnumInfo: {
enumValues: [
{
description: 'A test description',
name: 'TEST',
isDeprecated: true,
deprecationReason: 'This is deprecated',
},
],
},
colorEnumInfo: {
enumValues: [
{
description: 'A vivid color',
name: 'RED',
},
],
},
},
});
expect(mergedResult).to.deep.equal(enumResult);
Expand Down

0 comments on commit 84df7bd

Please sign in to comment.