-
Notifications
You must be signed in to change notification settings - Fork 2
/
generate-yaml.js
167 lines (162 loc) · 4.94 KB
/
generate-yaml.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
const yaml = require('js-yaml');
const fs = require('fs');
require('dotenv').config()
const hasuraPathKey = `${process.env.HASURA_INTEGRATION_HOST}/${process.env.API_KEY}/v1/graphql`.replace(/(\r\n|\n|\r)/gm, "");
const hasuraObject =
{
overwrite: true,
schema: [
{
[hasuraPathKey]: {
headers: { 'x-hasura-admin-secret': `${process.env.HASURA_ADMIN_SECRET}`.replace(/(\r\n|\n|\r)/gm, "") }
}
}
],
documents: './**/*.hasura.graphql',
generates: {
'./libs/database/src/graphql.hasura.types.ts': {
plugins: ['typescript'],
config: {
avoidOptionals: true,
strictScalars: true,
scalars: {
BigDecimal: 'string',
BigInt: 'string',
Bytes: 'string',
DateTime: 'string',
JSONObject: 'Record<string, unknown>',
uuid: 'string',
numeric: 'number',
timestamptz: 'string',
date:'string'
},
nonOptionalTypename: true,
useTypeImports: true,
inlineFragmentTypes: 'combine',
exportFragmentSpreadSubTypes: true,
useExplicitTyping: true
}
},
'./libs/database/src/': {
preset: 'near-operation-file',
presetConfig: {
baseTypesPath: './graphql.hasura.types.ts',
extension: '.operation.tsx',
folder: 'operations'
},
plugins: ['typescript-operations', 'typescript-react-apollo'],
config: {
defaultBaseOptions: { context: { clientName: 'hasura' } },
avoidOptionals: true,
onlyOperationTypes: true,
strictScalars: true,
scalars: {
BigDecimal: 'string',
BigInt: 'string',
Bytes: 'string',
DateTime: 'string',
JSONObject: 'Record<string, unknown>',
uuid: 'string',
numeric: 'number',
timestamptz: 'string',
timetz: 'string',
date:'string'
},
nonOptionalTypename: true,
useTypeImports: true,
inlineFragmentTypes: 'combine',
exportFragmentSpreadSubTypes: true,
useExplicitTyping: true,
withRefetchFn: true,
pureMagicComment: true
}
},
'./libs/database/src/graphql.hasura.helpers.ts': {
plugins: [
'named-operations-object',
'typescript-apollo-client-helpers',
'fragment-matcher'
],
config: {
useConsts: true,
useTypeImports: true,
requireKeyFields: true,
requirePoliciesForAllTypes: true
}
},
'./graphql.hasura.schema.json': { plugins: ['introspection'] }
}
}
// const graphObject =
// {
// overwrite: true,
// schema: `${process.env.GRAPH_MIDDLEWARE_HOST}/${process.env.API_KEY}/${process.env.GRAPH_MIDDLEWARE_PATH}`,
// documents: './**/*.graph.graphql',
// generates: {
// './libs/database/src/graphql.graph.types.ts': {
// plugins: [ 'typescript' ],
// config: {
// avoidOptionals: true,
// strictScalars: true,
// scalars: {
// BigDecimal: 'string',
// BigInt: 'string',
// Bytes: 'string',
// DateTime: 'string',
// JSONObject: 'Record<string, unknown>'
// },
// nonOptionalTypename: true,
// useTypeImports: true,
// inlineFragmentTypes: 'combine',
// exportFragmentSpreadSubTypes: true,
// useExplicitTyping: true
// }
// },
// './libs/database/src/': {
// preset: 'near-operation-file',
// presetConfig: {
// baseTypesPath: './graphql.graph.types.ts',
// extension: '.operation.tsx',
// folder: 'operations'
// },
// plugins: [ 'typescript-operations', 'typescript-react-apollo' ],
// config: {
// avoidOptionals: true,
// onlyOperationTypes: true,
// strictScalars: true,
// scalars: {
// BigDecimal: 'string',
// BigInt: 'string',
// Bytes: 'string',
// DateTime: 'string',
// JSONObject: 'Record<string, unknown>'
// },
// nonOptionalTypename: true,
// useTypeImports: true,
// inlineFragmentTypes: 'combine',
// exportFragmentSpreadSubTypes: true,
// useExplicitTyping: true,
// withRefetchFn: true,
// pureMagicComment: true
// }
// },
// './libs/database/src/graphql.graph.helpers.ts': {
// plugins: [
// 'named-operations-object',
// 'typescript-apollo-client-helpers',
// 'fragment-matcher'
// ],
// config: {
// useConsts: true,
// useTypeImports: true,
// requireKeyFields: true,
// requirePoliciesForAllTypes: true
// }
// },
// './graphql.graph.schema.json': { plugins: [ 'introspection' ] }
// }
// }
const res1 = yaml.dump(hasuraObject);
// const res2 = yaml.dump(graphObject);
fs.writeFileSync('codegen-hasura.yml', res1, {encoding: 'utf8'})
// fs.writeFileSync('codegen-graph.yml', res2, {encoding: 'utf8'})