-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcodegen.ts
More file actions
62 lines (57 loc) · 1.68 KB
/
Copy pathcodegen.ts
File metadata and controls
62 lines (57 loc) · 1.68 KB
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
import { config as loadEnv } from 'dotenv'
import type { CodegenConfig } from '@graphql-codegen/cli'
// Match Vite's env loading: .env.local overrides .env. Load .local first so
// already-set keys win, then .env fills in the rest.
loadEnv({ path: '.env.local' })
loadEnv({ path: '.env' })
const endpoint = process.env.VITE_GRAPHQL_ENDPOINT
const adminSecret = process.env.VITE_HASURA_ADMIN_SECRET
if (!endpoint) {
throw new Error(
'VITE_GRAPHQL_ENDPOINT is required for codegen. Set it in .env.local.'
)
}
if (!adminSecret) {
throw new Error(
'VITE_HASURA_ADMIN_SECRET is required for codegen. Set it in .env.local.'
)
}
const config: CodegenConfig = {
overwrite: true,
schema: [
{
[endpoint]: {
headers: {
'x-hasura-admin-secret': adminSecret,
},
},
},
],
documents: ['src/**/*.{ts,tsx,js,jsx}'],
generates: {
'src/schema/generated.ts': {
plugins: [
'typescript',
'typescript-operations',
'typed-document-node',
],
config: {
useTypeImports: true,
skipTypename: false,
avoidOptionals: false,
enumsAsTypes: true,
scalars: {
uuid: 'string',
bigint: 'number',
jsonb: 'unknown',
timestamptz: 'string',
timestamp: 'string',
date: 'string',
numeric: 'number',
},
},
},
},
ignoreNoDocuments: true,
}
export default config