Skip to content

Commit

Permalink
Augment typeDefs with cacheControl directive so SDL validation does…
Browse files Browse the repository at this point in the history
…n't fail
  • Loading branch information
martijnwalraven committed Sep 2, 2018
1 parent 884d44e commit 49d4ffb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All of the packages in the `apollo-server` repo are released with the same versi

### vNEXT
- Update graphql-playground-html to 1.7.4 [#1586](https://github.com/apollographql/apollo-server/pull/1586)
- Add support for `graphql-js` v14 by augmenting typeDefs with the `@cacheControl` directive so SDL validation doesn't fail [#1595](https://github.com/apollographql/apollo-server/pull/1595)

### v2.0.5

Expand Down
54 changes: 37 additions & 17 deletions packages/apollo-server-core/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,6 @@ export class ApolloServerBase {
}
}

//Add upload resolver
if (this.uploadsConfig) {
const { GraphQLUpload } = require('@apollographql/apollo-upload-server');
if (resolvers && !resolvers.Upload) {
resolvers.Upload = GraphQLUpload;
}
}

if (schema) {
this.schema = schema;
} else {
Expand All @@ -163,16 +155,44 @@ export class ApolloServerBase {
'Apollo Server requires either an existing schema or typeDefs',
);
}

let augmentedTypeDefs = Array.isArray(typeDefs) ? typeDefs : [typeDefs];

// We augment the typeDefs with the @cacheControl directive and associated
// scope enum, so makeExecutableSchema won't fail SDL validation
augmentedTypeDefs.push(
gql`
enum CacheControlScope {
PUBLIC
PRIVATE
}
directive @cacheControl(
maxAge: Int
scope: CacheControlScope
) on FIELD_DEFINITION | OBJECT | INTERFACE
`,
);

if (this.uploadsConfig) {
const {
GraphQLUpload,
} = require('@apollographql/apollo-upload-server');
if (resolvers && !resolvers.Upload) {
resolvers.Upload = GraphQLUpload;
}

// We augment the typeDefs with the Upload scalar, so typeDefs that
// don't include it won't fail
augmentedTypeDefs.push(
gql`
scalar Upload
`,
);
}

this.schema = makeExecutableSchema({
// we add in the upload scalar, so that schemas that don't include it
// won't error when we makeExecutableSchema
typeDefs: this.uploadsConfig
? [
gql`
scalar Upload
`,
].concat(typeDefs)
: typeDefs,
typeDefs: augmentedTypeDefs,
schemaDirectives,
resolvers,
});
Expand Down

0 comments on commit 49d4ffb

Please sign in to comment.