-
Notifications
You must be signed in to change notification settings - Fork 0
/
codegen.ts
92 lines (87 loc) · 3.41 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
import type { CodegenConfig } from "@graphql-codegen/cli";
import { addTypenameSelectionDocumentTransform } from "@graphql-codegen/client-preset";
const sharedConfig = {
skipTypename: true,
enumsAsTypes: true,
useTypeImports: true,
strictScalars: true,
scalars: {
DateTimeISO: "string",
Void: "void",
File: "@whatwg-node/fetch#File",
JSON: "object",
},
};
const sharedClientPresetConfig = {
...sharedConfig,
emitLegacyCommonJSImports: true,
arrayInputCoercion: false,
};
const mainConfig = {
documents: ["client/src/**/*.ts{,x}"],
preset: "client-preset" as const,
presetConfig: {
persistedDocuments: true,
},
config: {
...sharedClientPresetConfig,
},
documentTransforms: [addTypenameSelectionDocumentTransform],
};
const config: CodegenConfig = {
overwrite: true,
schema: "schema.graphql",
ignoreNoDocuments: true,
generates: {
"./client/src/util/graphql/introspection.json": {
plugins: ["client/src/util/graphql/urql-introspection-plugin.js"],
},
"./client/src/util/graphql/": mainConfig,
"./server/src/util/graphql/": mainConfig,
"./server/__test__/graphql/": {
documents: ["server/__test__/*.test.ts", "server/src/util/test.ts"],
preset: "client-preset",
presetConfig: {
fragmentMasking: false,
},
config: sharedClientPresetConfig,
},
"./server/src/types/schema.ts": {
plugins: ["typescript", "typescript-resolvers"],
config: {
...sharedConfig,
contextType: "../server#IContext",
typesPrefix: "T",
useIndexSignature: true,
extractAllFieldsToTypes: true,
mappers: {
Author: "./models#IAuthorModel",
Book: "./models#IBookModel",
Session: "./models#ISessionModel",
GuestUser: "./models#IGuestUserModel",
CitizenUser: "./models#ICitizenUserModel",
CompanyUser: "./models#ICompanyUserModel",
CompanyStatsFragment: "./models#ICompanyStatsFragmentModel",
Worktime: "./models#IWorktimeModel",
Employment: "./models#IEmploymentModel",
EmploymentOffer: "./models#IEmploymentOfferModel",
TransferTransaction: "./models#ITransferTransactionModel",
ChangeTransaction: "./models#IChangeTransactionModel",
ChangeDraft: "./models#IChangeDraftModel",
PurchaseTransaction: "./models#IPurchaseTransactionModel",
PurchaseDraft: "./models#IPurchaseDraftModel",
PurchaseItem: "./models#IPurchaseItemModel",
CustomsTransaction: "./models#ICustomsTransactionModel",
SalaryTransaction: "./models#ISalaryTransactionModel",
BorderCrossing: "./models#IBorderCrossingModel",
Stay: "./models#IStayModel",
Product: "./models#IProductModel",
ProductStatsFragment: "./models#IProductStatsFragmentModel",
Vote: "./models#IVoteModel",
Card: "./models#ICardModel",
},
},
},
},
};
export default config;