-
Notifications
You must be signed in to change notification settings - Fork 4
/
codegen.ts
107 lines (102 loc) · 2.65 KB
/
codegen.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import type { IGraphQLConfig } from "graphql-config";
const scalars = {
DateTime: "string",
Date: "string",
Decimal: "string",
Duration: "number",
JSON: "string",
Long: "number",
Time: "string",
TimeString: "string",
Upload: "unknown",
UUID: "string",
Void: "unknown",
GraphQLStringOrFloat: "string",
Hash: "unknown",
};
const gqlConfig = {
// TODO should change to true, but requires refactoring (not just type changes)
// why avoidOptionals is good? because it doesn't allow passing an invalid query result / fragment to a component
// generated fragments helps a lot with that, but there are still cases where it fails.
// With this on you have to explicitly set the field to null to pass it to a component or
// you know, query it properly from the server like you should in 99% of cases.
avoidOptionals: {
field: false,
inputValue: false,
object: false,
defaultValue: false,
},
// TODO this would improve linting fragments but it causes some issues in type generation
// experimentalFragmentVariables: true,
skipTypename: true,
defaultScalarType: "unknown",
scalars,
};
const schema = "http://localhost:8000/graphql/";
const plugins = [
"typescript",
"typescript-operations",
"typescript-react-apollo",
] as const;
const config: IGraphQLConfig = {
projects: {
common: {
schema,
documents: "packages/common/**/!(*.d|gql-types).{ts,tsx}",
extensions: {
codegen: {
config: gqlConfig,
generates: {
"packages/common/gql/gql-types.ts": {
plugins,
},
'tilavaraus.graphql': {
plugins: ['schema-ast'],
config: {
includeDirectives: true
},
},
},
hooks: {
afterOneFileWrite: ["prettier --write"],
},
},
},
},
"admin-ui": {
schema,
documents: "apps/admin-ui/**/!(*.d|gql-types).{ts,tsx}",
extensions: {
codegen: {
config: gqlConfig,
generates: {
"apps/admin-ui/gql/gql-types.ts": {
plugins,
},
},
hooks: {
afterOneFileWrite: ["prettier --write"],
},
},
},
},
ui: {
schema,
documents: "apps/ui/**/!(*.d|gql-types).{ts,tsx}",
extensions: {
codegen: {
config: gqlConfig,
generates: {
"apps/ui/gql/gql-types.ts": {
plugins,
},
},
hooks: {
afterOneFileWrite: ["prettier --write"],
},
},
},
},
},
};
export default config;