Query Guide

Common Queries

Query Vault Data

query getVaultData($vaultId: ID!) {
  vault(id: $vaultId) {
    id
    totalAssets
    pricePerShare
    strategies {
      id
      name
      totalDebt
      totalGain
      isActive
    }
    harvests(orderBy: timestamp, orderDirection: desc, first: 10) {
      timestamp
      gain
      loss
    }
  }
}

Query User Account Data

query getUserData($accountId: ID!) {
  account(id: $accountId) {
    id
    vaultBalances {
      vault {
        id
        underlyingToken {
          symbol
        }
      }
      shareBalance
      netDeposits
    }
    deposits(orderBy: timestamp, orderDirection: desc) {
      amount
      timestamp
    }
  }
}

Query Strategy Performance

query getStrategyPerformance($strategyId: ID!) {
  strategy(id: $strategyId) {
    id
    name
    totalGain
    totalLoss
    isActive
    vault {
      id
      totalAssets
    }
  }
}


Developer Resources

Real-time Updates

Subscribe to real-time updates using GraphQL subscriptions:

subscription onHarvest {
  harvest(orderBy: timestamp, orderDirection: desc) {
    id
    strategy {
      name
    }
    gain
    loss
    timestamp
  }
}

Error Handling

The subgraph API uses the standard GraphQL error format. Common error scenarios:

  1. Entity Not Found: Returns null for the requested entity

  2. Invalid Query: Returns a GraphQL validation error

  3. Network Issues: Check the _meta field for indexing status

Example error check:

query checkIndexingStatus {
  _meta {
    hasIndexingErrors
    block {
      number
    }
  }
}

Rate Limits and Best Practices

  1. Implement pagination for large result sets using first and skip parameters

  2. Use specific field selection instead of requesting all fields

  3. Cache frequently accessed data client-side

  4. Monitor your query complexity and response times

  5. Consider implementing retry logic for failed queries

SDK Integration

For TypeScript/JavaScript applications, you can generate typed clients using:

  • GraphQL Code Generator

  • Apollo Codegen

  • URQL Codegen

Example type generation command:

graphql-codegen --config codegen.yml

Last updated