Skip to content

Commit

Permalink
fix(agent): defend against graph-node bug #5550 (null paused)
Browse files Browse the repository at this point in the history
  • Loading branch information
dwerner committed Aug 2, 2024
1 parent 65cdec5 commit 5d36a5e
Showing 1 changed file with 39 additions and 11 deletions.
50 changes: 39 additions & 11 deletions packages/indexer-common/src/graph-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ export const parseGraphQLChain = (chain: any): ChainIndexingStatus => ({
export const parseGraphQLBlockPointer = (block: any): BlockPointer | null =>
block
? {
number: +block.number,
hash: block.hash,
}
number: +block.number,
hash: block.hash,
}
: null

export class GraphNode {
Expand Down Expand Up @@ -149,18 +149,47 @@ export class GraphNode {
): Promise<SubgraphDeploymentAssignment[]> {
try {
this.logger.debug('Fetch subgraph deployment assignments')
const result = await this.status

// FIXME: remove this initial check for just node when graph-node releases
// https://github.com/graphprotocol/graph-node/pull/5551
const nodeOnlyResult = await this.status
.query(gql`
{
indexingStatuses {
subgraphDeployment: subgraph
node
paused
}
}
`)
.toPromise()

if (nodeOnlyResult.error) {
throw nodeOnlyResult.error
}

const withAssignments: string[] = nodeOnlyResult.data.indexingStatuses
.filter((result: QueryResult) => {
return result.node !== undefined
})
.map((result: QueryResult) => {
return result.subgraphDeployment
})

const result = await this.status
.query(
gql`
{
indexingStatuses($subgraphs) {
subgraphDeployment: subgraph
node
paused
}
}
`,
{ subgraphs: withAssignments },
)
.toPromise()

if (result.error) {
throw result.error
}
Expand All @@ -174,7 +203,7 @@ export class GraphNode {

type QueryResult = {
subgraphDeployment: string
node: string
node: string | undefined
paused: boolean | undefined
}

Expand Down Expand Up @@ -240,9 +269,9 @@ export class GraphNode {
node
? node.deployments.push(status.subgraphDeployment)
: indexNodes.push({
id: status.node,
deployments: [status.subgraphDeployment],
})
id: status.node,
deployments: [status.subgraphDeployment],
})
},
)

Expand Down Expand Up @@ -636,8 +665,7 @@ export class GraphNode {

if (!result.data || !result.data.blockHashFromNumber || result.error) {
throw new Error(
`Failed to query graph node for blockHashFromNumber: ${
result.error ?? 'no data returned'
`Failed to query graph node for blockHashFromNumber: ${result.error ?? 'no data returned'
}`,
)
}
Expand Down

0 comments on commit 5d36a5e

Please sign in to comment.