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

Federation: Preserve @deprecated type-system directives #3792

Merged
merged 4 commits into from
Feb 14, 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
2 changes: 1 addition & 1 deletion packages/apollo-federation/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});
3 changes: 3 additions & 0 deletions packages/apollo-federation/src/composition/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
Expand Down