-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcodegen.ts
More file actions
executable file
·89 lines (82 loc) · 2.88 KB
/
Copy pathcodegen.ts
File metadata and controls
executable file
·89 lines (82 loc) · 2.88 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
/**
* GraphQL Code Generator Configuration
*
* This file generates TypeScript types from GraphQL schemas for all protocol adapters.
*
* IMPORTANT: All schema URLs are imported from protocol config files to maintain
* a single source of truth. Never hardcode URLs here - update the config files instead:
* - AAVE: src/lib/protocols/aave/v3/config.ts (AAVE_V3_API_URL)
* - Morpho: src/lib/protocols/morpho/v1/config.ts (MORPHO_V1_API_URL)
* - Compound: src/lib/protocols/compound/v3/config.ts (COMPOUND_V3_CHAINS[chainId].custom.subgraphUrl)
*/
import type { CodegenConfig } from '@graphql-codegen/cli'
import { config as loadEnv } from 'dotenv'
import { mainnet, optimism } from 'viem/chains'
import { COMPOUND_V3_CHAINS } from './src/lib/protocols/compound/v3/config'
// Load environment variables from .env file
loadEnv({ path: ['.env', '.env.local'] })
// Extract API URLs from configs (single source of truth)
const compoundV3EthereumSubgraphUrl =
COMPOUND_V3_CHAINS[mainnet.id]?.custom?.subgraphUrl
const compoundV3OptimismSubgraphUrl =
COMPOUND_V3_CHAINS[optimism.id]?.custom?.subgraphUrl
if (!compoundV3EthereumSubgraphUrl || !compoundV3OptimismSubgraphUrl) {
throw new Error(
'Compound V3 subgraph URL not found in config. Please update src/lib/protocols/compound/config.ts'
)
}
const config: CodegenConfig = {
overwrite: true,
config: {
// Ensure generated files have proper type annotations
useTypeImports: true,
},
generates: {
// AAVE V3 - Offchain (GraphQL API)
// Schema URL is imported from src/lib/protocols/aave/v3/config.ts
'src/lib/protocols/aave/v3/generated/': {
schema: 'src/lib/protocols/aave/v3/schema.json',
documents: 'src/lib/protocols/aave/v3/queries.ts',
preset: 'client',
presetConfig: {
fragmentMasking: false,
},
},
// COMPOUND V3 - Onchain (Subgraph)
// Schema URL is imported from src/lib/protocols/compound/v3/config.ts
'src/lib/protocols/compound/v3/generated/': {
schema: [
{
[compoundV3EthereumSubgraphUrl]: {
headers: process.env.THEGRAPH_API_KEY
? {
Authorization: `Bearer ${process.env.THEGRAPH_API_KEY}`,
}
: {},
},
},
],
documents: 'src/lib/protocols/compound/v3/queries.ts',
preset: 'client',
presetConfig: {
fragmentMasking: false,
},
},
// MORPHO V1 - Offchain (GraphQL API)
// Schema URL is imported from src/lib/protocols/morpho/v1/config.ts
'src/lib/protocols/morpho/v1/generated/': {
schema: 'src/lib/protocols/morpho/v1/schema.json',
documents: 'src/lib/protocols/morpho/v1/queries.ts',
preset: 'client',
presetConfig: {
fragmentMasking: false,
},
config: {
namingConvention: {
enumValues: 'keep',
},
},
},
},
}
export default config