-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
plugins-example.ts
90 lines (83 loc) · 2.18 KB
/
plugins-example.ts
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { printSchema } from 'https://cdn.skypack.dev/graphql@v15.5.0?dts';
import DirectivesPlugin from './packages/plugin-directives/mod.ts';
import MocksPlugin from './packages/plugin-mocks/mod.ts';
import RelayPlugin from './packages/plugin-relay/mod.ts';
import ScopeAuthPlugin from './packages/plugin-scope-auth/mod.ts';
import SimpleObjectsPlugin from './packages/plugin-simple-objects/mod.ts';
import SmartSubscriptionsPlugin from './packages/plugin-smart-subscriptions/mod.ts';
import SubGraphPlugin from './packages/plugin-sub-graph/mod.ts';
import ValidationPlugin from './packages/plugin-validation/mod.ts';
import DataloaderPlugin from './packages/plugin-dataloader/mod.ts';
import SchemaBuilder from './packages/core/mod.ts';
const builder = new SchemaBuilder<{
AuthScopes: {
user: boolean;
};
}>({
plugins: [
ValidationPlugin,
ScopeAuthPlugin,
SubGraphPlugin,
SmartSubscriptionsPlugin,
SimpleObjectsPlugin,
RelayPlugin,
MocksPlugin,
DirectivesPlugin,
DataloaderPlugin,
],
relayOptions: {
nodeTypeOptions: {},
nodeQueryOptions: {},
nodesQueryOptions: {},
pageInfoTypeOptions: {},
},
authScopes: () => ({
user: true,
}),
smartSubscriptions: {
subscribe: () => {},
unsubscribe: () => {},
},
subGraphs: {
defaultForFields: ['test'],
defaultForTypes: ['test'],
},
});
builder.queryType({
fields: (t) => ({
hello: t.string({
smartSubscription: true,
args: {
name: t.arg.string({
validate: {
minLength: 3,
},
}),
},
authScopes: {
user: true,
},
resolve(_root, { name }) {
return `hello, ${name || 'world'}`;
},
}),
}),
});
builder.simpleObject('Simple', {
fields: (t) => ({
test: t.boolean({}),
}),
});
builder.loadableObject('User', {
load: (keys: string[]) => {
return Promise.resolve(
keys.map((id) => (Number(id) > 0 ? { id: Number(id) } : new Error(`Invalid ID ${id}`))),
);
},
fields: (t) => ({
id: t.exposeID('id', {}),
}),
});
builder.subscriptionType({});
const schema = builder.toSchema({ mocks: {}, subGraph: 'test' });
console.log(printSchema(schema));