Skip to content

Commit

Permalink
feat: continue working on indexer's absence (#2248)
Browse files Browse the repository at this point in the history
* feat: continue working on indexer's absence

* feat: treat 'none' and 'NONE' as equals
  • Loading branch information
kilted-andres authored Jan 6, 2025
1 parent b1210a0 commit 27b856b
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions src/backend/revoker/indexer/queryFromIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,30 @@ export async function queryFromIndexer<ExpectedQueryResults>(query: string) {
logger.debug(
`Querying from GraphQL under ${indexer.graphqlEndpoint}, using this payload: ${query} `,
);
const { data } = await got
.post(indexer.graphqlEndpoint, {
json: {
query,
},
})
.json<FetchedData<ExpectedQueryResults>>();

const responsePromise = got.post(indexer.graphqlEndpoint, {
json: {
query,
},
});

// handle bad responses
try {
await responsePromise;
} catch (error) {
logger.error(
`Error response coming from ${indexer.graphqlEndpoint}: ${JSON.stringify(error, null, 2)}`,
);
logger.info(`Continuing as if there where no matches to the query.`);
return {
totalCount: 0,
matches: Array.of<ExpectedQueryResults>(),
};
}

// handle good responses
const { data } =
await responsePromise.json<FetchedData<ExpectedQueryResults>>();

const entities = Object.entries(data);

Expand Down Expand Up @@ -81,7 +98,7 @@ export async function queryFromIndexer<ExpectedQueryResults>(query: string) {
export async function* matchesGenerator<ExpectedQueryResults>(
buildQuery: (offset: number) => string,
): AsyncGenerator<ExpectedQueryResults, void> {
if (indexer.graphqlEndpoint === 'NONE') {
if (String(indexer.graphqlEndpoint).toUpperCase() === 'NONE') {
return;
}
const query = buildQuery(0);
Expand Down

0 comments on commit 27b856b

Please sign in to comment.