Query Guide

Introduction

This guide provides examples and best practices for querying the Kodiak Islands subgraph using GraphQL. Whether you're building a dashboard, analysis tool, or integrating with another application, these queries will help you extract the data you need.

Getting Started

To query the Kodiak Islands subgraph, you'll need to:

  1. Know the subgraph endpoint URL (sugraph-endpoint)

  2. Have a basic understanding of GraphQL query syntax

  3. Use a GraphQL client (like Apollo Client) or make HTTP requests to the endpoint

Basic Query Structure

All GraphQL queries for the Kodiak Islands subgraph follow this basic structure:

query {
  entity(where: { filter conditions }) {
    field1
    field2
    nestedEntity {
      nestedField1
      nestedField2
    }
  }
}

Common Query Examples

1. Protocol Overview

Get basic information about the protocol:

2. List All Vaults

Retrieve all vaults with basic information:

3. Get Vault Details

Get detailed information about a specific vault:

4. Recent Deposits

Query recent deposit events for a specific vault:

5. Recent Withdrawals

Query recent withdrawal events for a specific vault:

6. Daily Vault Performance

Query daily snapshots for a vault to analyze performance over time:

7. Protocol Usage Metrics

Query daily protocol usage metrics:

8. Protocol Financial Metrics

Query daily protocol financial metrics:

9. Strategy Changes

Track strategy changes for a specific vault:

10. Vault APR History

Query APR history for a vault:

Filtering and Sorting

Time-Based Filtering

Filter snapshots within a specific time range:

Value-Based Filtering

Filter vaults by TVL:

Sorting Results

Sort vaults by TVL in descending order:

Pagination

For large result sets, use pagination with first and skip:

Advanced Queries

Get User Activity Across Vaults

Find all deposits and withdrawals for a specific user:

Compare Multiple Vaults

Compare performance metrics for multiple vaults:

Best Practices

  1. Query Only What You Need: Only request the fields you actually need to minimize response size.

  2. Use Pagination: For large collections, always use pagination to prevent timeouts.

  3. Filter Efficiently: Apply filters at the query level rather than filtering results in your application.

  4. Optimize Sorting: Sort at the query level for better performance.

  5. Cache Results: GraphQL responses are highly cacheable. Implement client-side caching for better performance.

  6. Handle Time Data Correctly: Remember that timestamps are in seconds since Unix epoch.

Error Handling

The subgraph may return errors for various reasons:

  • Invalid query syntax

  • Non-existent entities or fields

  • Server timeouts for complex queries

Always implement proper error handling in your application to handle these cases gracefully.

Real-World Use Cases

Building a Dashboard

For a vault performance dashboard, you might combine protocol metrics with vault-specific data:

Historical Analysis

For analyzing a vault's performance over time:

With these query examples and best practices, you should be well-equipped to extract valuable data from the Kodiak Islands subgraph for your applications.

Last updated