-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathyoga.ts
More file actions
38 lines (35 loc) · 891 Bytes
/
yoga.ts
File metadata and controls
38 lines (35 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { createSchema, createYoga, type Plugin } from 'graphql-yoga';
import { usePersistedOperations } from '@graphql-yoga/plugin-persisted-operations';
const schema = createSchema({
typeDefs: /* GraphQL */ `
type Query {
hello: String!
}
type Mutation {
echo(message: String!): String!
}
`,
resolvers: {
Query: {
hello: () => 'Hello world!',
},
Mutation: {
echo: (_, args) => args.message,
},
},
});
export function makeYoga(args: { persistedDocuments: null | Map<string, string> }) {
const plugins: Array<Plugin<any, any, any>> = [];
if (args.persistedDocuments !== null) {
const { persistedDocuments } = args;
plugins.push(
usePersistedOperations({
getPersistedOperation: hash => persistedDocuments.get(hash) ?? null,
}),
);
}
return createYoga({
schema,
plugins,
});
}