Skip to content

Commit

Permalink
[Federation] Allow specified directives during validation (apollograp…
Browse files Browse the repository at this point in the history
…hql/apollo-server#2823)

The keyFieldsMissingExternal validator should permit standard
directives just like we do in composition everywhere else.
Apollo-Orig-Commit-AS: apollographql/apollo-server@4415648
  • Loading branch information
trevor-scheer committed Jun 11, 2019
1 parent 5e573b1 commit 1f03e2a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 2 additions & 0 deletions federation-js/CHANGELOG.md
Expand Up @@ -2,6 +2,8 @@

### vNEXT

* Allow specified directives during validation (@deprecated) [#2823](https://github.com/apollographql/apollo-server/pull/2823)

# v0.6.1

* Normalize SDL in a normalization step before validation [#2771](https://github.com/apollographql/apollo-server/pull/2771)
Expand Up @@ -51,6 +51,37 @@ describe('keyFieldsMissingExternal', () => {
expect(warnings).toHaveLength(0);
});

it('has no warnings with @deprecated directive usage', () => {
const serviceA = {
typeDefs: gql`
extend type Car @key(fields: "model { name kit { upc } } year") {
model: Model! @external
year: String! @external
color: String! @deprecated(reason: "Use colors instead")
colors: Color!
}
extend type Model {
name: String! @external
kit: Kit @external
}
extend type Kit {
upc: String! @external
}
enum Color {
Red
Blue
}
`,
name: 'serviceA',
};

const warnings = validateKeyFieldsMissingExternal(serviceA);
expect(warnings).toHaveLength(0);
});

it("warns when a @key argument doesn't reference an @external field", () => {
const serviceA = {
typeDefs: gql`
Expand Down
Expand Up @@ -5,6 +5,7 @@ import {
parse,
GraphQLSchema,
GraphQLError,
specifiedDirectives,
} from 'graphql';
import { buildSchemaFromSDL } from 'apollo-graphql';
import { isNotNullOrUndefined } from 'apollo-env';
Expand Down Expand Up @@ -58,7 +59,7 @@ export const keyFieldsMissingExternal = ({
// this allows us to build a partial schema
let schema = new GraphQLSchema({
query: undefined,
directives: federationDirectives,
directives: [...specifiedDirectives, ...federationDirectives],
});
try {
schema = buildSchemaFromSDL(typeDefs, schema);
Expand Down

0 comments on commit 1f03e2a

Please sign in to comment.