> For the complete documentation index, see [llms.txt](https://devs.maxapy.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://devs.maxapy.io/maxapy-erc4626/subgraph/query-guide.md).

# Query Guide

## Common Queries <a href="#common-queries" id="common-queries"></a>

### Query Vault Data <a href="#query-vault-data" id="query-vault-data"></a>

```graphql
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 <a href="#query-user-account-data" id="query-user-account-data"></a>

```graphql
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 <a href="#query-strategy-performance" id="query-strategy-performance"></a>

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

***

## Developer Resources <a href="#developer-resources" id="developer-resources"></a>

### Real-time Updates <a href="#real-time-updates" id="real-time-updates"></a>

Subscribe to real-time updates using GraphQL subscriptions:

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

### Error Handling <a href="#error-handling" id="error-handling"></a>

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:

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

### Rate Limits and Best Practices <a href="#rate-limits-and-best-practices" id="rate-limits-and-best-practices"></a>

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 <a href="#sdk-integration" id="sdk-integration"></a>

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

* GraphQL Code Generator
* Apollo Codegen
* URQL Codegen

Example type generation command:

```bash
graphql-codegen --config codegen.yml
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://devs.maxapy.io/maxapy-erc4626/subgraph/query-guide.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
