Skip to content

Commit 378cce6

Browse files
author
Stephen Barlow
authored
Merge pull request #5022 from apollographql/sb/custom-directive-edits
First batch of edits to custom directives article
2 parents 851cdba + e78b9ee commit 378cce6

File tree

5 files changed

+373
-136
lines changed

5 files changed

+373
-136
lines changed

docs/gatsby-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ module.exports = {
7575
],
7676
Appendices: [
7777
'proxy-configuration',
78-
'migration-two-dot',
78+
'installing-graphql-tools',
7979
'migration-file-uploads',
8080
'migration-engine-plugins',
8181
],

docs/source/api/graphql-tools.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ sidebar_title: graphql-tools
55

66
The `graphql-tools` library enables the creation and manipulation of GraphQL schema. Apollo Server is able to accept a `schema` that has been enabled by `graphql-tools`. Apollo server directly exports all the function from `graphql-tools`, enabling a migration path for more complicated use cases.
77

8-
> Apollo Server uses `graphql-tools` version 4. For documentation of the _latest_ version of `graphql-tools`, see the [official `graphql-tools` documentation](https://www.graphql-tools.com/docs/introduction).
8+
> Apollo Server includes `graphql-tools` version 4. To use another version of the library, see [Using a different version of graphql-tools](../installing-graphql-tools/).
99
1010
```js
1111
const { makeExecutableSchema } = require('apollo-server');
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
title: Using a different version of graphql-tools
3+
---
4+
5+
Apollo Server includes `graphql-tools` version 4 by default. If you want to use a newer version, you can do so with the following steps:
6+
7+
1. Install `graphql-tools` separately in your project.
8+
9+
2. Update your `ApolloServer` constructor to provide the `schema` option _instead of_ `typeDefs`, `resolvers`, and `schemaDirectives`. You instead pass these options to the `makeExecutableSchema` function, which you provide as the value of `schema`:
10+
11+
```js:title=index.js
12+
const { ApolloServer, gql } = require("apollo-server");
13+
const { makeExecutableSchema } = require("@graphql-tools/schema");
14+
15+
const server = new ApolloServer({
16+
schema: makeExecutableSchema({
17+
typeDefs,
18+
resolvers,
19+
schemaDirectives: {
20+
// ...directive subclasses...
21+
}
22+
}),
23+
// ...other options...
24+
});
25+
```
26+
27+
3. Add the following definitions to your schema `typeDefs`:
28+
29+
```graphql:title=schema.graphql
30+
enum CacheControlScope {
31+
PUBLIC
32+
PRIVATE
33+
}
34+
35+
directive @cacheControl(
36+
maxAge: Int
37+
scope: CacheControlScope
38+
) on FIELD_DEFINITION | OBJECT | INTERFACE
39+
40+
scalar Upload
41+
```
42+
43+
Apollo Server uses these types for its [caching](./performance/caching/) and [file upload](./data/file-uploads/) functionality. It usually defines these types automatically on startup, but it _doesn't_ if you provide the `schema` option to the `ApolloServer` constructor.
44+
45+
For more information on the latest version of `graphql-tools`, see the [official documentation](https://www.graphql-tools.com/docs/introduction/).

0 commit comments

Comments
 (0)