-
Notifications
You must be signed in to change notification settings - Fork 8
/
codegen.ts
75 lines (72 loc) · 2.03 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
/* eslint-disable @typescript-eslint/no-var-requires */
import type { CodegenConfig } from '@graphql-codegen/cli';
import * as prismaEnumsBase from '@prisma/client';
require('dotenv').config();
const prismaEnums = Object.keys(prismaEnumsBase)
// Remove non-objects and uppercased keys
.filter(
(key) =>
typeof prismaEnumsBase[key] === 'object' &&
key[0] !== key[0].toUpperCase()
)
// Transform object to union type
.reduce(
(acc, curr) => ({
...acc,
[curr]: Object.keys(prismaEnumsBase[curr])
.map((el) => `"${el}"`)
.join(' | '),
}),
{} as Record<keyof typeof prismaEnumsBase, string>
);
const config: CodegenConfig = {
overwrite: true,
documents: [],
generates: {
'./src/services/hasura/types.ts': {
schema: {
[`${process.env.HASURA_ENDPOINT}`]: {
headers: {
'x-hasura-admin-secret': process.env.HASURA_ADMIN_SECRET as string,
},
},
},
documents: 'src/services/hasura/**/*.gql',
plugins: [
{
add: {
content: [
'/* eslint-disable */',
`export type Notification_Type = ${prismaEnums.notification_type};`,
],
},
},
'typescript',
'typescript-operations',
'typescript-graphql-request',
'typescript-resolvers',
],
config: {
scalars: {
_text: 'string',
// TODO: Fix all type errors on build when enabling next line
// ...prismaEnums,
_notification_type: `Array<Notification_Type>`,
manual_task_event_type: prismaEnums.manual_task_event_type,
task_type: prismaEnums.task_type,
key_status: prismaEnums.key_status,
},
skipTypename: true,
defaultMapper: 'Partial<{T}>',
avoidOptionals: {
field: true,
inputValue: false,
object: true,
defaultValue: true,
},
fetcher: 'graphql-request',
},
},
},
};
export default config;