diff --git a/packages/apollo-federation/CHANGELOG.md b/packages/apollo-federation/CHANGELOG.md index 6673974e47a..88dd6d4a5a0 100644 --- a/packages/apollo-federation/CHANGELOG.md +++ b/packages/apollo-federation/CHANGELOG.md @@ -4,7 +4,7 @@ > The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the the appropriate changes within that release will be moved into the new section. -- _Nothing yet! Stay tuned._ +- Fix `v0.12.0` regression: Preserve the `@deprecated` type-system directive as a special case when removing type system directives during composition, resolving an unintentional breaking change introduced by [#3736](https://github.com/apollographql/apollo-server/pull/3736). [#3792](https://github.com/apollographql/apollo-server/pull/3792) ## v0.12.0 diff --git a/packages/apollo-federation/src/composition/__tests__/composeAndValidate.test.ts b/packages/apollo-federation/src/composition/__tests__/composeAndValidate.test.ts index f3e20cec8bf..9cb3206d71e 100644 --- a/packages/apollo-federation/src/composition/__tests__/composeAndValidate.test.ts +++ b/packages/apollo-federation/src/composition/__tests__/composeAndValidate.test.ts @@ -623,4 +623,32 @@ describe('composition of schemas with directives', () => { `societal: String!`, ); }); + + it(`doesn't strip the special case @deprecated type-system directive`, () => { + const serviceA = { + typeDefs: gql` + type EarthConcern { + environmental: String! + } + + extend type Query { + importantDirectives: [EarthConcern!]! + @deprecated(reason: "Don't remove me please") + } + `, + name: 'serviceA', + }; + + const { schema, errors } = composeAndValidate([serviceA]); + expect(errors).toHaveLength(0); + + const deprecated = schema.getDirective('deprecated'); + expect(deprecated).toMatchInlineSnapshot(`"@deprecated"`); + + const queryType = schema.getType('Query') as GraphQLObjectType; + const field = queryType.getFields()['importantDirectives']; + + expect(field.isDeprecated).toBe(true); + expect(field.deprecationReason).toEqual("Don't remove me please"); + }); }); diff --git a/packages/apollo-federation/src/composition/utils.ts b/packages/apollo-federation/src/composition/utils.ts index 34ca9b06aa8..9422f29c102 100644 --- a/packages/apollo-federation/src/composition/utils.ts +++ b/packages/apollo-federation/src/composition/utils.ts @@ -86,6 +86,9 @@ export function stripExternalFieldsFromTypeDefs( export function stripTypeSystemDirectivesFromTypeDefs(typeDefs: DocumentNode) { const typeDefsWithoutTypeSystemDirectives = visit(typeDefs, { Directive(node) { + // The `deprecated` directive is an exceptional case that we want to leave in + if (node.name.value === 'deprecated') return; + const isFederationDirective = federationDirectives.some( ({ name }) => name === node.name.value, );