This guide covers common query patterns, optimization techniques, and best practices for retrieving data from the Panda Protocol subgraph.
Basic Queries
Pool Data
# Get basic pool information{ pandaPool(id: "0x123...") { id price volumeUSD swapsCount graduated }}# List active pools with high volume{ pandaPools( where: {volumeUSD_gt: "100000",graduated: false } orderBy: volumeUSD orderDirection: desc first: 10 ) { id price volumeUSD }}
# Using skip/first for pagination{ pandaPoolSwaps( skip: 100 # Skip first 100 results first: 50 # Get next 50 results orderBy: timestamp orderDirection: desc ) { id timestamp }}
Field Selection
# Good: Specific fields{ pandaPools { id price volumeUSD }}# Bad: Overfetching{ pandaPools { id price volumeUSD swapsCount lastSwapTimestamp graduated raised # ... unnecessary fields }}
# Query at specific block{ pandaPool(id: "0x123...", block: { number: 15000000 }) { price volumeUSD }}
Error Handling
Null Checks
# Handle potential null values{ pandaPool(id: "0x123...") { id # Will be null if pool doesn't exist price # Always check optional relationships swaps(first: 1) { id } }}
Block Timestamps
# Use block timestamps for time ranges{ pandaPoolSwaps( where: {timestamp_gt: "1634567890",timestamp_lt: "1634567990" } ) { timestamp averagePrice }}