Skip to content

Commit 002e769

Browse files
author
Thomas De Meyer
committed
docs: add README sections for Apollo Trusted Documents Plugin and Apollo Gateway Packages
1 parent ea303a9 commit 002e769

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Apollo Gateway Packages
2+
3+
A collection of plugins and integrations for Apollo Server and Apollo Gateway.
4+
5+
## Packages
6+
7+
### [@labdigital/apollo-gateway-directives](./packages/gateway-directives)
8+
9+
A plugin that allows you to handle GraphQL directives within Apollo Gateway.
10+
11+
### [@labdigital/apollo-server-integration-fastify](./packages/integration-fastify)
12+
13+
A plugin to integrate Apollo Server with Fastify.
14+
15+
### [@labdigital/apollo-trusted-documents](./packages/trusted-documents)
16+
17+
A plugin that enables support for trusted documents (persisted queries) in Apollo Server, with built-in support for GraphQL Hive's App Deployments.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Apollo Trusted Documents Plugin
2+
3+
This plugin enables support for trusted documents (persisted queries) in Apollo Server, with built-in support for GraphQL Hive's App Deployments.
4+
5+
## Installation
6+
7+
```bash
8+
pnpm add @labdigital/apollo-trusted-documents
9+
```
10+
11+
## Usage
12+
13+
### With GraphQL Hive
14+
15+
```ts
16+
import { ApolloServer } from "@apollo/server";
17+
import { TrustedDocumentsPlugin, HiveStore } from "@labdigital/apollo-trusted-documents";
18+
import Keyv from "keyv";
19+
20+
// Create a cache for the documents (e.g., using Keyv)
21+
const cache = new Keyv();
22+
23+
const trustedDocumentsPlugin = new TrustedDocumentsPlugin({
24+
store: new HiveStore({
25+
endpoint: "https://cdn.graphql-hive.com",
26+
accessToken: process.env.HIVE_CDN_ACCESS_TOKEN,
27+
cache,
28+
}),
29+
// Optional: strict mode (default: true)
30+
// When enabled, only trusted documents are allowed
31+
strict: true,
32+
// Optional: bypass header for development/testing
33+
bypassHeader: "x-bypass-trusted-operations",
34+
bypassSecret: process.env.BYPASS_SECRET,
35+
});
36+
37+
const server = new ApolloServer({
38+
typeDefs,
39+
resolvers,
40+
plugins: [trustedDocumentsPlugin],
41+
});
42+
43+
await server.start();
44+
```
45+
46+
### Custom Document Store
47+
48+
You can implement your own document store by implementing the `DocumentStore` interface:
49+
50+
```ts
51+
import type { DocumentStore } from "@labdigital/apollo-trusted-documents";
52+
53+
class MyCustomStore implements DocumentStore {
54+
async get(documentId: string): Promise<string | undefined> {
55+
// Fetch the document from your custom store
56+
return myDatabase.getDocument(documentId);
57+
}
58+
}
59+
60+
const trustedDocumentsPlugin = new TrustedDocumentsPlugin({
61+
store: new MyCustomStore(),
62+
});
63+
```
64+
65+
## Options
66+
67+
| Option | Type | Default | Description |
68+
|--------|------|---------|-------------|
69+
| `store` | `DocumentStore` | - | The document store to use for fetching trusted documents |
70+
| `strict` | `boolean` | `true` | When enabled, only trusted documents are allowed |
71+
| `bypassHeader` | `string` | `"x-bypass-trusted-operations"` | Header name to check for bypass secret |
72+
| `bypassSecret` | `string` | - | Secret value to allow bypassing trusted documents check |

0 commit comments

Comments
 (0)