-
Notifications
You must be signed in to change notification settings - Fork 5
/
codegen.js
105 lines (101 loc) · 3.65 KB
/
codegen.js
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const baseClientConfig = {
withComponent: false,
withHOC: false,
withHooks: true,
nonOptionalTypename: true,
federation: true,
}
const clientMutationSuccessAdd = {
add: {
content: [
`type ThenArg<T> = T extends PromiseLike<infer U> ? U : T`,
`export type MutationSuccessResponse<T extends (...args: any[]) => any[]> = ThenArg<ReturnType<ThenArg<ReturnType<T>>[0]>>`,
],
},
}
const clientGenerates = {
'packages/frontend/admin/src/graphql/index.tsx': {
documents: 'packages/frontend/admin/src/graphql/**/*.graphql',
schema: 'http://localhost:3000/graphql',
plugins: ['typescript', 'typescript-operations', 'typescript-react-apollo', clientMutationSuccessAdd],
config: baseClientConfig,
},
'packages/frontend/app/src/graphql/index.tsx': {
documents: 'packages/frontend/app/src/graphql/**/*.graphql',
schema: 'http://localhost:3000/graphql',
plugins: ['typescript', 'typescript-operations', 'typescript-react-apollo', clientMutationSuccessAdd],
config: baseClientConfig,
},
'packages/frontend/gatsby-theme-luminate/src/graphql/index.tsx': {
documents: 'packages/frontend/gatsby-theme-luminate/src/graphql/**/*.graphql',
schema: 'http://localhost:3000/graphql',
plugins: ['typescript', 'typescript-operations', 'typescript-react-apollo', clientMutationSuccessAdd],
config: baseClientConfig,
},
}
const serverGenerates = {
'packages/backend/api/src/types.d.ts': {
schema: ['./packages/backend/api/src/application/**/!(index.ts)*.graphql'],
plugins: ['typescript', 'typescript-resolvers'],
config: {
contextType: './application/ApplicationModule#Context',
useIndexSignature: true,
},
},
'packages/backend/utils/graphql/src/types.ts': {
plugins: ['typescript'],
},
'packages/backend/services/identity/schema/src/types.d.ts': {
schema: ['./packages/backend/services/identity/schema/src/application/**/!(index.ts)*.graphql'],
plugins: ['typescript', 'typescript-resolvers'],
config: {
contextType: './startServer#Context',
useIndexSignature: true,
federation: true,
//mappers: {
//Role: './infra/models#RoleDocument',
//User: './infra/models#UserDocument',
//Me: './infra/models#UserDocument',
//},
},
},
'packages/backend/services/encyclopedia/schema/src/types.d.ts': {
schema: ['./packages/backend/services/encyclopedia/schema/src/application/**/!(index.ts)*.graphql'],
plugins: ['typescript', 'typescript-resolvers'],
config: {
contextType: './startServer#Context',
useIndexSignature: true,
federation: true,
//mappers: {
//Coffee: './models#CoffeeDocument',
//Country: './models#CountryDocument',
//Farm: './models#FarmDocument',
//Note: './models#NoteDocument',
//Region: './models#RegionDocument',
//Variety: './models#VarietyDocument',
//},
},
},
'packages/backend/services/brewing/schema/src/types.d.ts': {
schema: ['./packages/backend/services/brewing/schema/src/**/!(index.ts)*.graphql'],
plugins: ['typescript', 'typescript-resolvers'],
config: {
contextType: './startServer#Context',
useIndexSignature: true,
federation: true,
mappers: {
CuppingSession: './models#CuppingSessionDocument',
SessionCoffee: './models#SessionCoffeeDocument',
ScoreSheet: './models#ScoreSheetDocument',
},
},
},
}
module.exports = {
schema: ['./packages/backend/utils/graphql/src/schema/**/*.ts'],
generates: Object.assign(
{},
process.argv.find(arg => arg === '--client') ? clientGenerates : null,
process.argv.find(arg => arg === '--server') ? serverGenerates : null,
),
}