-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcodegen.ts
More file actions
62 lines (55 loc) · 1.68 KB
/
Copy pathcodegen.ts
File metadata and controls
62 lines (55 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 { CodegenConfig } from '@graphql-codegen/cli';
const generatedTargetFiles = {
headlessCms: 'src/domain/headlessCms/graphql/__generated__.ts',
kukkuuBackend: 'src/domain/api/generatedTypes/graphql.tsx',
} as const;
const headlessCmsDocuments = ['src/**/cms*.ts'];
const excludeDocuments = (documents: string[]) =>
documents.map((document) => `!${document}`);
type Props = {
schema: string;
documents: string[];
targetFile: string;
};
const makeGeneratesConfig = ({ schema, documents, targetFile }: Props) => ({
[targetFile]: {
schema,
documents,
plugins: ['typescript', 'typescript-operations', 'typescript-react-apollo'],
config: {
withHooks: false,
withComponent: false,
flattenSelectionSet: true,
avoidOptionals: {
field: true,
object: true,
},
dedupeOperationSuffix: true,
},
hooks: { afterOneFileWrite: ['prettier --write'] },
},
});
const config: CodegenConfig = {
generates: {
...makeGeneratesConfig({
schema:
process.env.VITE_API_URI ?? 'https://kukkuu.api.test.hel.ninja/graphql',
documents: [
'src/**/*.ts',
// Exclude documents from headless CMS:
...excludeDocuments(headlessCmsDocuments),
// Exclude the generated type files as sources
...excludeDocuments(Object.values(generatedTargetFiles)),
],
targetFile: generatedTargetFiles.kukkuuBackend,
}),
...makeGeneratesConfig({
schema:
process.env.VITE_CMS_URI ??
'https://kukkuu.app-staging.hkih.hion.dev/graphql',
documents: [...headlessCmsDocuments],
targetFile: generatedTargetFiles.headlessCms,
}),
},
};
export default config;