-
Notifications
You must be signed in to change notification settings - Fork 0
/
codegen.ts
100 lines (92 loc) · 2.39 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
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
import * as process from "node:process";
import { type CodegenConfig } from "@graphql-codegen/cli";
import { type IGraphQLConfig } from "graphql-config";
import { invariant } from "./src/lib/invariant";
export const baseCodegenConfig: CodegenConfig["config"] = {
avoidOptionals: {
defaultValue: false,
field: true,
inputValue: false,
object: false,
},
dedupeFragments: true,
dedupeOperationSuffix: true,
documentMode: "string",
enumsAsTypes: true,
exportFragmentSpreadSubTypes: true,
extractAllFieldsToTypes: true,
mergeFragmentTypes: true,
omitOperationSuffix: true,
scalars: {
Date: "string",
DateTime: "string",
Day: "number",
Decimal: "number",
GenericScalar: "unknown",
JSON: "unknown",
JSONString: "string",
Metadata: "Record<string, string>",
Minute: "number",
PositiveDecimal: "number",
UUID: "string",
Upload: "unknown",
WeightScalar: "unknown",
_Any: "unknown",
},
skipTypename: true,
strictScalars: true,
useTypeImports: true,
};
const addContent = [
"// @ts-nocheck",
"// prettier-ignore",
"/* eslint-disable */",
"/* @typescript-eslint/no-unused-vars */",
];
invariant(process.env.SALEOR_URL, "SALEOR_URL not set.");
const schemaUrl = new URL(process.env.SALEOR_URL).origin;
const config: IGraphQLConfig = {
projects: {
default: {
documents: ["./src/**/*.graphql"],
extensions: {
codegen: {
generates: {
"./src/graphql/": {
config: baseCodegenConfig,
plugins: [
"typescript-operations",
"typed-document-node",
{
add: {
content: addContent,
},
},
],
preset: "near-operation-file-preset",
presetConfig: {
baseTypesPath: "./schema",
extension: ".ts",
fileName: "generated",
},
},
"./src/graphql/schema.ts": {
config: baseCodegenConfig,
plugins: [
"typescript",
{
add: {
content: addContent,
},
},
],
},
},
overwrite: true,
},
},
schema: `${schemaUrl}/graphql/`,
},
},
};
export default config;