📈Subgraph Queries

Complete guide to querying DreamLend protocol data using The Graph subgraph. Access real-time and historical data for loans, users, and protocol statistics.

🌐 Subgraph Endpoint

GraphQL Endpoint: https://api.subgraph.somnia.network/api/public/d5671b32-2846-489e-a577-e7d9702dd17b/subgraphs/dreamlend-graph/v0.0.3/

Playground: Open GraphQL Playgroundarrow-up-right

📊 Entity Schema

Loan Entity

type Loan @entity {
  id: ID!
  lender: Bytes!
  borrower: Bytes
  tokenAddress: Bytes!
  amount: BigInt!
  interestRate: BigInt!
  duration: BigInt!
  collateralAddress: Bytes!
  collateralAmount: BigInt!
  minCollateralRatioBPS: BigInt!
  liquidationThresholdBPS: BigInt!
  maxPriceStaleness: BigInt!
  status: LoanStatus!
  startTime: BigInt
  repaidAmount: BigInt!
  blockNumber: BigInt!
  blockTimestamp: BigInt!
  transactionHash: Bytes!
}

User Entity

ProtocolStats Entity

🔍 Common Queries

Get All Active Loans

Get Pending Loan Offers

Get User's Loans

Get Loan Details

Get Protocol Statistics

Get User Statistics

Get Loans by Token

Get Recent Liquidations

Get Loans with Filters

📊 Advanced Queries

Get Loan History with Events

Get Top Lenders

Get Market Overview

🛠️ JavaScript Integration

Using Apollo Client

Using Fetch API

React Hook Example

📋 Query Parameters

Filtering

  • where: Filter entities by field values

  • where_not: Exclude entities matching criteria

  • where_gt/gte/lt/lte: Numeric comparisons

  • where_in/not_in: Array membership

Sorting

  • orderBy: Field to sort by

  • orderDirection: asc or desc

Pagination

  • first: Number of entities to return (max 1000)

  • skip: Number of entities to skip

  • last: Get last N entities

Example with All Parameters

🔄 Real-time Updates

Subscriptions (if supported)

Polling Strategy

🎯 Best Practices

Performance Optimization

  1. Limit Results: Always use first parameter

  2. Specific Fields: Only query fields you need

  3. Proper Indexing: Use indexed fields for filtering

  4. Batch Queries: Combine related queries

Error Handling

Caching Strategy


For more examples and integration patterns, see our Developer Integration Guidearrow-up-right.

Last updated