Skip to content

Commit

Permalink
agent, common, service: use checkedQuery instead of query
Browse files Browse the repository at this point in the history
  • Loading branch information
tilacog committed Sep 6, 2023
1 parent 44373cc commit 72a742a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/indexer-agent/src/syncing-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const createSyncingServer = async ({

let result
try {
result = await networkSubgraph.query(parsedQuery, variables)
result = await networkSubgraph.checkedQuery(parsedQuery, variables)
} catch (err) {
logger.error(err)
return res.status(400).send({ error: err.message })
Expand Down
26 changes: 13 additions & 13 deletions packages/indexer-common/src/indexer-management/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class NetworkMonitor {
}

async allocation(allocationID: string): Promise<Allocation> {
const result = await this.networkSubgraph.query(
const result = await this.networkSubgraph.checkedQuery(
gql`
query allocation($allocation: String!) {
allocation(id: $allocation) {
Expand Down Expand Up @@ -100,7 +100,7 @@ export class NetworkMonitor {
async allocations(status: AllocationStatus): Promise<Allocation[]> {
try {
this.logger.debug(`Fetch ${status} allocations`)
const result = await this.networkSubgraph.query(
const result = await this.networkSubgraph.checkedQuery(
gql`
query allocations($indexer: String!, $status: AllocationStatus!) {
allocations(
Expand Down Expand Up @@ -161,7 +161,7 @@ export class NetworkMonitor {

async epochs(epochNumbers: number[]): Promise<Epoch[]> {
try {
const result = await this.networkSubgraph.query(
const result = await this.networkSubgraph.checkedQuery(
gql`
query epochs($epochs: [Int!]!) {
epoches(where: { id_in: $epochs }, first: 1000) {
Expand Down Expand Up @@ -201,7 +201,7 @@ export class NetworkMonitor {
): Promise<Allocation[]> {
try {
this.logger.debug('Fetch recently closed allocations')
const result = await this.networkSubgraph.query(
const result = await this.networkSubgraph.checkedQuery(
gql`
query allocations($indexer: String!, $closedAtEpochThreshold: Int!) {
allocations(
Expand Down Expand Up @@ -264,7 +264,7 @@ export class NetworkMonitor {
subgraphDeploymentId: SubgraphDeploymentID,
): Promise<Allocation[]> {
try {
const result = await this.networkSubgraph.query(
const result = await this.networkSubgraph.checkedQuery(
gql`
query allocations($indexer: String!, $subgraphDeploymentId: String!) {
allocations(
Expand Down Expand Up @@ -350,7 +350,7 @@ export class NetworkMonitor {
subgraphIds: ids,
})
try {
const result = await this.networkSubgraph.query(
const result = await this.networkSubgraph.checkedQuery(
gql`
query subgraphs($first: Int!, $lastCreatedAt: Int!, $subgraphs: [String!]!) {
subgraphs(
Expand Down Expand Up @@ -436,7 +436,7 @@ export class NetworkMonitor {

async subgraphDeployment(ipfsHash: string): Promise<SubgraphDeployment | undefined> {
try {
const result = await this.networkSubgraph.query(
const result = await this.networkSubgraph.checkedQuery(
gql`
query subgraphDeployments($ipfsHash: String!) {
subgraphDeployments(where: { ipfsHash: $ipfsHash }) {
Expand Down Expand Up @@ -494,7 +494,7 @@ export class NetworkMonitor {
async transferredDeployments(): Promise<TransferredSubgraphDeployment[]> {
this.logger.debug('Querying the Network for transferred subgraph deployments')
try {
const result = await this.networkSubgraph.query(
const result = await this.networkSubgraph.checkedQuery(
// TODO: Consider querying for the same time range as the Agent's evaluation, limiting
// results to recent transfers.
gql`
Expand Down Expand Up @@ -592,7 +592,7 @@ export class NetworkMonitor {
queryProgress: queryProgress,
})
try {
const result = await this.networkSubgraph.query(
const result = await this.networkSubgraph.checkedQuery(
gql`
query subgraphDeployments($first: Int!, $lastCreatedAt: Int!) {
subgraphDeployments(
Expand Down Expand Up @@ -670,7 +670,7 @@ export class NetworkMonitor {
const queryEpochSubgraph = async () => {
// We know it is non-null because of the check above for a null case that will end execution of fn if true
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const result = await this.epochSubgraph!.query(
const result = await this.epochSubgraph!.checkedQuery(
gql`
query network($networkID: String!) {
network(id: $networkID) {
Expand Down Expand Up @@ -935,7 +935,7 @@ Please submit an issue at https://github.com/graphprotocol/block-oracle/issues/n
.reduce(async (currentlyPaused) => {
try {
logger.debug('Query network subgraph isPaused state')
const result = await networkSubgraph.query(
const result = await networkSubgraph.checkedQuery(
gql`
{
graphNetworks {
Expand Down Expand Up @@ -1013,7 +1013,7 @@ Please submit an issue at https://github.com/graphprotocol/block-oracle/issues/n
closedAtEpoch_lte: disputableEpoch,
queryFeesCollected_gte: this.indexerOptions.rebateClaimThreshold.toString(),
})
const result = await this.networkSubgraph.query(
const result = await this.networkSubgraph.checkedQuery(
gql`
query allocations(
$indexer: String!
Expand Down Expand Up @@ -1127,7 +1127,7 @@ Please submit an issue at https://github.com/graphprotocol/block-oracle/issues/n
const disputableEpoch = currentEpoch - this.indexerOptions.poiDisputableEpochs
let lastCreatedAt = 0
while (dataRemaining) {
const result = await this.networkSubgraph.query(
const result = await this.networkSubgraph.checkedQuery(
gql`
query allocations(
$deployments: [String!]!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@ async function queryAllocations(
)
}

const result = await networkSubgraph.query(ALLOCATION_QUERIES[filterType], filterVars)
const result = await networkSubgraph.checkedQuery(
ALLOCATION_QUERIES[filterType],
filterVars,
)

if (result.data.allocations.length == 0) {
logger.info(`No 'Claimable' allocations found`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default {
const address = network.specification.indexerOptions.address

try {
const result = await network.networkSubgraph.query(
const result = await network.networkSubgraph.checkedQuery(
gql`
query allocations($indexer: String!) {
allocations(
Expand Down
2 changes: 1 addition & 1 deletion packages/indexer-common/src/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ export class TransactionManager {
return timer(60_000)
.reduce(async (currentlyPaused) => {
try {
const result = await networkSubgraph.query(
const result = await networkSubgraph.checkedQuery(
gql`
{
graphNetworks {
Expand Down
4 changes: 2 additions & 2 deletions packages/indexer-service/src/allocations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const monitorEligibleAllocations = ({
logger.debug('Refresh eligible allocations')

try {
const currentEpochResult = await networkSubgraph.query(
const currentEpochResult = await networkSubgraph.checkedQuery(
gql`
query {
graphNetwork(id: "1") {
Expand All @@ -61,7 +61,7 @@ export const monitorEligibleAllocations = ({

const currentEpoch = currentEpochResult.data.graphNetwork.currentEpoch

const result = await networkSubgraph.query(
const result = await networkSubgraph.checkedQuery(
gql`
query allocations($indexer: String!, $closedAtEpochThreshold: Int!) {
indexer(id: $indexer) {
Expand Down

0 comments on commit 72a742a

Please sign in to comment.