Skip to content

Commit

Permalink
common: setting up GraphQL using Yoga and Codegen preset
Browse files Browse the repository at this point in the history
  • Loading branch information
saihaj committed Feb 21, 2024
1 parent 94a81a6 commit 2ca42af
Show file tree
Hide file tree
Showing 67 changed files with 9,322 additions and 58 deletions.
14 changes: 14 additions & 0 deletions packages/indexer-common/codegen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { CodegenConfig } from '@graphql-codegen/cli'
import { defineConfig } from '@eddeee888/gcg-typescript-resolver-files'

const config: CodegenConfig = {
schema: 'src/indexer-management/schema.graphql',
generates: {
'src/schema': defineConfig({
typesPluginsConfig: {
contextType: '@graphprotocol/indexer-common#IndexerManagementResolverContext',
},
}),
},
}
export default config
6 changes: 5 additions & 1 deletion packages/indexer-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"test:ci": "LOG_LEVEL=info jest --verbose --maxWorkers=1 --ci",
"test:debug": "LOG_LEVEL=debug jest --runInBand --detectOpenHandles --verbose",
"test:watch": "jest --runInBand --detectOpenHandles --watch --passWithNoTests --verbose",
"clean": "rm -rf ./node_modules ./dist ./tsconfig.tsbuildinfo"
"clean": "rm -rf ./node_modules ./dist ./tsconfig.tsbuildinfo",
"codegen": "graphql-codegen --config codegen.ts"
},
"dependencies": {
"@graphprotocol/common-ts": "2.0.9",
Expand All @@ -39,6 +40,7 @@
"fastify": "3.25.0",
"graphql": "16.8.0",
"graphql-tag": "2.12.6",
"graphql-yoga": "^5.1.1",
"jayson": "3.6.6",
"lodash.clonedeep": "^4.5.0",
"lodash.groupby": "^4.6.0",
Expand All @@ -58,6 +60,8 @@
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
"@eddeee888/gcg-typescript-resolver-files": "^0.7.2",
"@graphql-codegen/cli": "^5.0.2",
"@types/cors": "2.8.14",
"@types/express": "4.17.17",
"@types/jest": "29.5.4",
Expand Down
11 changes: 1 addition & 10 deletions packages/indexer-common/src/indexer-management/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,7 @@ import { BigNumber } from 'ethers'
import { Op, Sequelize } from 'sequelize'
import { GraphNode } from '../graph-node'
import { ActionManager, MultiNetworks, Network } from '@graphprotocol/indexer-common'

export interface IndexerManagementResolverContext {
models: IndexerManagementModels
graphNode: GraphNode
logger: Logger
defaults: IndexerManagementDefaults
actionManager: ActionManager | undefined
multiNetworks: MultiNetworks<Network> | undefined
dai: WritableEventual<string>
}
import { IndexerManagementResolverContext } from './context'

const SCHEMA_SDL = gql`
scalar BigInt
Expand Down
15 changes: 15 additions & 0 deletions packages/indexer-common/src/indexer-management/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Logger, WritableEventual } from '@graphprotocol/common-ts'
import { IndexerManagementModels } from './models'
import { GraphNode } from '../graph-node'
import { ActionManager, MultiNetworks, Network } from '@graphprotocol/indexer-common'
import { IndexerManagementDefaults } from './client'

export interface IndexerManagementResolverContext {
models: IndexerManagementModels
graphNode: GraphNode
logger: Logger
defaults: IndexerManagementDefaults
actionManager: ActionManager | undefined
multiNetworks: MultiNetworks<Network> | undefined
dai: WritableEventual<string>
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/ban-types */
import { IndexerManagementResolverContext } from '../client'
import { IndexerManagementResolverContext } from '../context'
import { Logger } from '@graphprotocol/common-ts'
import {
Action,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
GraphQLCostModel,
parseGraphQLCostModel,
} from '../models'
import { IndexerManagementResolverContext } from '../client'
import { IndexerManagementResolverContext } from '../context'
import { compileAsync } from '@graphprotocol/cost-model'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import geohash from 'ngeohash'
import gql from 'graphql-tag'
import { IndexerManagementResolverContext } from '../client'
import { IndexerManagementResolverContext } from '../context'
import { SubgraphDeploymentID } from '@graphprotocol/common-ts'
import {
indexerError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
IndexingRuleIdentifier,
IndexingRuleCreationAttributes,
} from '../models'
import { IndexerManagementDefaults, IndexerManagementResolverContext } from '../client'
import { IndexerManagementDefaults } from '../client'
import { IndexerManagementResolverContext } from '../context'
import { Transaction } from 'sequelize/types'
import { fetchIndexingRules } from '../rules'
import { processIdentifier } from '../../'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/ban-types */

import { POIDispute, POIDisputeIdentifier, POIDisputeCreationAttributes } from '../models'
import { IndexerManagementResolverContext } from '../client'
import { IndexerManagementResolverContext } from '../context'
import { validateNetworkIdentifier } from '../../parsers'
import { Op, WhereOptions } from 'sequelize'
import groupBy from 'lodash.groupby'
Expand Down
Loading

0 comments on commit 2ca42af

Please sign in to comment.