Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions codegen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
56 changes: 0 additions & 56 deletions codegen.yml

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"build": "craco build",
"test": "craco test",
"eject": "react-scripts eject",
"generate": "graphql-codegen --config codegen.yml -r dotenv/config",
"generate": "graphql-codegen --config codegen.ts -r dotenv/config",
"codegen:schema": "npx apollo client:download-schema --endpoint=https://api.thegraph.com/subgraphs/name/ianlapham/uniswap-v3-rinkeby",
"codegen:generate": "apollo codegen:generate --localSchemaFile=schema.json --target=typescript --includes=src/**/*.ts --tagName=gql --addTypename --globalTypesFile=src/types/graphql-global-types.ts types"
},
Expand Down
23 changes: 14 additions & 9 deletions src/apollo/generated/fragmentMetadata.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"possibleTypes": {
"GqlPoolAprValue": ["GqlPoolAprRange", "GqlPoolAprTotal"],
"GqlPoolBase": [
"GqlPoolComposableStable",
"GqlPoolElement",
"GqlPoolFixedPriceLBP",
"GqlPoolFx",
"GqlPoolGyro",
"GqlPoolLiquidityBootstrapping",
"GqlPoolLiquidityBootstrappingV3",
"GqlPoolMetaStable",
"GqlPoolQuantAmmWeighted",
"GqlPoolReClamm",
"GqlPoolStable",
"GqlPoolWeighted"
],
Expand All @@ -16,23 +19,25 @@
"GqlPoolSwapEventCowAmm",
"GqlPoolSwapEventV3"
],
"GqlPoolFeaturedPoolGroupItem": [
"GqlFeaturePoolGroupItemExternalLink",
"GqlPoolMinimal"
],
"GqlPoolNestedUnion": ["GqlPoolComposableStableNested"],
"GqlPoolTokenBase": ["GqlPoolToken", "GqlPoolTokenComposableStable"],
"GqlPoolTokenComposableStableNestedUnion": ["GqlPoolToken"],
"GqlPoolTokenUnion": ["GqlPoolToken", "GqlPoolTokenComposableStable"],
"GqlPoolUnion": [
"GqlPoolComposableStable",
"GqlPoolElement",
"GqlPoolFixedPriceLBP",
"GqlPoolFx",
"GqlPoolGyro",
"GqlPoolLiquidityBootstrapping",
"GqlPoolLiquidityBootstrappingV3",
"GqlPoolMetaStable",
"GqlPoolQuantAmmWeighted",
"GqlPoolReClamm",
"GqlPoolStable",
"GqlPoolWeighted"
],
"HookParams": [
"ExitFeeHookParams",
"FeeTakingHookParams",
"MevTaxHookParams",
"StableSurgeHookParams"
]
}
}
Loading