Skip to content

Commit

Permalink
common: let indexerEndpoints route be filtered by protocol network
Browse files Browse the repository at this point in the history
  • Loading branch information
tilacog committed Aug 10, 2023
1 parent de55495 commit b24b820
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/indexer-common/src/indexer-management/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ const SCHEMA_SDL = gql`
indexerRegistration(protocolNetwork: String!): IndexerRegistration!
indexerDeployments: [IndexerDeployment]!
indexerAllocations(protocolNetwork: String!): [IndexerAllocation]!
indexerEndpoints(protocolNetwork: String!): [IndexerEndpoints!]!
indexerEndpoints(protocolNetwork: String): [IndexerEndpoints!]!
costModels(deployments: [String!]): [CostModel!]!
costModel(deployment: String!): CostModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import geohash from 'ngeohash'
import gql from 'graphql-tag'
import { IndexerManagementResolverContext } from '../client'
import { SubgraphDeploymentID } from '@graphprotocol/common-ts'
import { indexerError, IndexerErrorCode, Network } from '@graphprotocol/indexer-common'
import {
indexerError,
IndexerErrorCode,
Network,
validateNetworkIdentifier,
} from '@graphprotocol/indexer-common'
import { extractNetwork } from './utils'
interface Test {
test: (url: string) => string
Expand Down Expand Up @@ -57,7 +62,7 @@ const URL_VALIDATION_TEST: Test = {

export default {
indexerRegistration: async (
{ protocolNetwork: unvalidateProtocolNetwork }: { protocolNetwork: string },
{ protocolNetwork: unvalidatedProtocolNetwork }: { protocolNetwork: string },
{ multiNetworks }: IndexerManagementResolverContext,
): Promise<object | null> => {
if (!multiNetworks) {
Expand All @@ -66,7 +71,7 @@ export default {
)
}

const network = extractNetwork(unvalidateProtocolNetwork, multiNetworks)
const network = extractNetwork(unvalidatedProtocolNetwork, multiNetworks)
const protocolNetwork = network.specification.networkIdentifier
const address = network.specification.indexerOptions.address
const contracts = network.contracts
Expand Down Expand Up @@ -163,7 +168,7 @@ export default {
},

indexerEndpoints: async (
{ protocolNetwork }: { protocolNetwork: string },
{ protocolNetwork: unvalidatedProtocolNetwork }: { protocolNetwork: string | null },
{ multiNetworks, logger }: IndexerManagementResolverContext,
): Promise<Endpoints[] | null> => {
if (!multiNetworks) {
Expand All @@ -172,7 +177,27 @@ export default {
)
}
const endpoints: Endpoints[] = []
let networkIdentifier: string | null = null

// Validate protocol network
try {
if (unvalidatedProtocolNetwork) {
networkIdentifier = validateNetworkIdentifier(unvalidatedProtocolNetwork)
}
} catch (parseError) {
throw new Error(
`Invalid protocol network identifier: '${unvalidatedProtocolNetwork}'. Error: ${parseError}`,
)
}

await multiNetworks.map(async (network: Network) => {
// Skip if this query asks for another protocol network
if (
networkIdentifier &&
networkIdentifier !== network.specification.networkIdentifier
) {
return
}
try {
const networkEndpoints = await endpointForNetwork(network)
endpoints.push(networkEndpoints)
Expand Down

0 comments on commit b24b820

Please sign in to comment.