-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodegen.ts
46 lines (40 loc) · 1.09 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
import type { CodegenConfig } from '@graphql-codegen/cli';
import dotenv from 'dotenv';
dotenv.config();
interface ProcessEnv {
VITE_SUPABASE_URL: string;
VITE_SUPABASE_ANON_KEY: string;
}
const ENV = process.env as unknown as ProcessEnv;
if (!ENV.VITE_SUPABASE_URL || !ENV.VITE_SUPABASE_ANON_KEY)
throw new Error('Invalid Supabase URL or Anon Key. Check your env variables');
const config: CodegenConfig = {
overwrite: true,
schema: {
[`${ENV.VITE_SUPABASE_URL}/graphql/v1`]: {
headers: {
apiKey: ENV.VITE_SUPABASE_ANON_KEY,
},
},
},
documents: 'src/**/*.gql',
generates: {
'src/graphql/generated/types.ts': {
plugins: ['typescript'],
},
'src/graphql/generated/operations.ts': {
preset: 'import-types',
presetConfig: { typesPath: './types' },
plugins: ['typescript-operations'],
},
'src/graphql/generated/hooks.ts': {
preset: 'import-types',
presetConfig: {
typesPath: './operations',
withMutationFn: true,
},
plugins: ['typescript-react-apollo'],
},
},
};
export default config;