-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcodegen.ts
More file actions
136 lines (125 loc) · 3.71 KB
/
codegen.ts
File metadata and controls
136 lines (125 loc) · 3.71 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import type { CodegenConfig } from "@graphql-codegen/cli";
const graphKey = process.env.REACT_APP_PERSONAL_GRAPH_KEY;
const blocksSubgraph = "9A6bkprqEG2XsZUYJ5B2XXp6ymz9fNcn4tVPxMWDztYC";
const balancerV2Subgraph =
"C4ayEZP2yTXRAB8vSaTrgN4m9anTe9Mdm2ViyiAuV9TV";
const gaugesDeployment = "QmNrMRgSeUUkQsvhE6ExBEPETZ6P2jiJL3SzXftNQcAEcW";
function theGraphSchema(subgraphId: string) {
return {
[`https://gateway.thegraph.com/api/subgraphs/id/${subgraphId}`]: {
headers: {
Authorization: `Bearer ${graphKey}`,
},
},
};
}
function theGraphDeployment(deploymentId: string) {
return {
[`https://gateway.thegraph.com/api/deployments/id/${deploymentId}`]: {
headers: {
Authorization: `Bearer ${graphKey}`,
},
},
};
}
const config: CodegenConfig = {
schema: [
theGraphSchema(blocksSubgraph),
theGraphSchema(balancerV2Subgraph),
theGraphDeployment(gaugesDeployment),
"https://api-v3.balancer.fi/",
],
documents: [
"src/data/blocks/*.gql",
"src/data/balancer/*.gql",
"src/data/balancer-gauges/*.gql",
"src/data/balancer-api-v3/*.gql",
],
hooks: {
afterAllFileWrite: ["prettier --write"],
},
generates: {
// Generates a full copy of the remote schema
"src/apollo/generated/schema.graphql": {
plugins: ["schema-ast"],
},
// Generates fragment metadata needed by apollo cache
"src/apollo/generated/fragmentMetadata.json": {
plugins: ["fragment-matcher"],
},
// Generates query and mutation documents
"src/apollo/generated/operations.ts": {
plugins: ["typescript-document-nodes"],
},
// Generates query and mutation documents and types for ethereum-blocks and balancer-v2 subgraphs
"src/apollo/generated/graphql-codegen-generated.ts": {
schema: [
theGraphSchema(blocksSubgraph),
theGraphSchema(balancerV2Subgraph),
],
documents: [
"src/data/balancer/*.gql",
"src/data/blocks/*.gql",
],
plugins: [
{ add: { content: "/* tslint:disable */" } },
"typescript",
"typescript-operations",
"typescript-react-apollo",
"fragment-matcher",
],
config: {
declarationKind: "interface",
enumsAsTypes: true,
nonOptionalTypename: true,
preResolveTypes: true,
scalars: {
BigInt: "string",
BigDecimal: "string",
Bytes: "string",
},
},
},
// Generates query and mutation documents and types for balancer gauges subgraph
"src/apollo/generated/graphql-gauges-codegen-generated.ts": {
schema: [
theGraphDeployment(gaugesDeployment),
],
documents: ["src/data/balancer-gauges/*.gql"],
plugins: [
{ add: { content: "/* tslint:disable */" } },
"typescript",
"typescript-operations",
"typescript-react-apollo",
"fragment-matcher",
],
config: {
declarationKind: "interface",
enumsAsTypes: true,
nonOptionalTypename: true,
preResolveTypes: true,
scalars: {
BigInt: "string",
BigDecimal: "string",
Bytes: "string",
},
},
},
// Generates query and mutation documents and types for balancer v3 API
"src/apollo/generated/graphql-balancer-v3-codegen-generated.ts": {
schema: ["https://api-v3.balancer.fi/"],
documents: ["src/data/balancer-api-v3/*.gql"],
plugins: [
{ add: { content: "/* tslint:disable */" } },
"typescript",
"typescript-operations",
"typescript-react-apollo",
"fragment-matcher",
],
config: {
declarationKind: "interface",
},
},
},
};
export default config;