Skip to content

GraphQL Proxy (Work in Progress - Unstable)

Pass-through GraphQL queries to Inodra-managed Sui nodes with schema introspection enabled.

Overview

The GraphQL proxy forwards your requests to Sui's GraphQL infrastructure.

Endpoint: https://api.inodra.com/v1/graphql

Quick Start

1. Basic Setup

javascript
const GRAPHQL_URL = 'https://api.inodra.com/v1/graphql'
const API_KEY = 'YOUR_API_KEY'

async function queryGraphQL(query, variables = {}) {
  const response = await fetch(GRAPHQL_URL, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'x-api-key': API_KEY
    },
    body: JSON.stringify({ query, variables })
  })

  return response.json()
}

2. Your First Query

javascript
const query = `
  query LatestCheckpoints {
    checkpoints(last: 5) {
      nodes {
        sequenceNumber
        timestamp
        networkTotalTransactions
      }
    }
  }
`

const result = await queryGraphQL(query)
console.log('Latest checkpoints:', result.data.checkpoints.nodes)

The official Sui SDK provides SuiGraphQLClient with type-safe queries:

typescript
import { SuiGraphQLClient } from '@mysten/sui/graphql'
import { graphql } from '@mysten/sui/graphql/schemas/latest'

const client = new SuiGraphQLClient({
  url: 'https://api.inodra.com/v1/graphql',
  headers: { 'x-api-key': 'YOUR_API_KEY' }
})

// Type-safe query with autocomplete
const chainQuery = graphql(`
  query {
    chainIdentifier
  }
`)

const result = await client.query({ query: chainQuery })
console.log('Chain:', result.data?.chainIdentifier)

The graphql() function provides compile-time type checking for your queries, catching errors before runtime.

Querying Checkpoints with the SDK

typescript
const checkpointsQuery = graphql(`
  query LatestCheckpoints {
    checkpoints(last: 5) {
      nodes {
        sequenceNumber
        timestamp
        networkTotalTransactions
      }
    }
  }
`)

const result = await client.query({ query: checkpointsQuery })
console.log('Checkpoints:', result.data?.checkpoints?.nodes)

Common Query Examples

Get Transaction Details

graphql
query GetTransaction($digest: String!) {
  transactionBlock(digest: $digest) {
    digest
    sender {
      address
    }
    gasInput {
      gasSponsor {
        address
      }
      gasPrice
      gasBudget
    }
    effects {
      status
      errors
      gasEffects {
        gasObject {
          owner {
            __typename
          }
        }
      }
    }
  }
}

Get Address Balance

graphql
query AddressBalance($address: SuiAddress!) {
  address(address: $address) {
    address
    balance {
      totalBalance
    }
    transactionBlocks(first: 10) {
      nodes {
        digest
        sender {
          address
        }
      }
    }
  }
}

Query Events

graphql
query RecentEvents($eventType: String!) {
  events(filter: { eventType: $eventType }, first: 50) {
    nodes {
      sendingModule {
        package {
          address
        }
        name
      }
      type {
        repr
      }
      sender {
        address
      }
      timestamp
      json
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}

Pagination

GraphQL uses cursor-based pagination:

javascript
async function getAllTransactions(address) {
  let allTransactions = []
  let hasNextPage = true
  let cursor = null

  while (hasNextPage) {
    const query = `
      query PaginatedTransactions($address: SuiAddress!, $after: String) {
        address(address: $address) {
          transactionBlocks(first: 50, after: $after) {
            nodes {
              digest
              effects {
                status
              }
            }
            pageInfo {
              hasNextPage
              endCursor
            }
          }
        }
      }
    `

    const result = await queryGraphQL(query, { address, after: cursor })
    const txData = result.data.address.transactionBlocks

    allTransactions.push(...txData.nodes)
    hasNextPage = txData.pageInfo.hasNextPage
    cursor = txData.pageInfo.endCursor
  }

  return allTransactions
}

Using with GraphQL Clients

Apollo Client

javascript
import { ApolloClient, InMemoryCache, createHttpLink } from '@apollo/client'
import { setContext } from '@apollo/client/link/context'

const httpLink = createHttpLink({
  uri: 'https://api.inodra.com/v1/graphql'
})

const authLink = setContext((_, { headers }) => ({
  headers: {
    ...headers,
    'x-api-key': 'YOUR_API_KEY'
  }
}))

const client = new ApolloClient({
  link: authLink.concat(httpLink),
  cache: new InMemoryCache()
})

urql

javascript
import { Client, cacheExchange, fetchExchange } from 'urql'

const client = new Client({
  url: 'https://api.inodra.com/v1/graphql',
  exchanges: [cacheExchange, fetchExchange],
  fetchOptions: {
    headers: {
      'x-api-key': 'YOUR_API_KEY'
    }
  }
})

Error Handling

javascript
async function safeGraphQLQuery(query, variables = {}) {
  try {
    const result = await queryGraphQL(query, variables)

    if (result.errors) {
      console.error('GraphQL Errors:', result.errors)
      throw new Error(`GraphQL Errors: ${result.errors.map((e) => e.message).join(', ')}`)
    }

    return result.data
  } catch (error) {
    console.error('Query failed:', error)
    throw error
  }
}

GraphQL Schema Reference

Inodra proxies to Sui's official GraphQL API. For the complete schema documentation, including all available types, fields, and arguments, refer to:

Advantages

🎯 Flexible Queries

  • Request exactly the data you need
  • Reduce over-fetching and under-fetching
  • Single request for complex data requirements

🔧 Developer Experience

  • Strong type system with schema validation
  • Excellent tooling support and IDE integration
  • Self-documenting API

🚀 Managed Service

  • No node setup required
  • Usage tracking in the dashboard

When to Use GraphQL Proxy

Perfect for:

  • Applications needing flexible, complex queries
  • Frontend applications with varying data requirements
  • Reducing number of API calls with nested queries
  • Projects already using GraphQL in their stack

Next Steps

Ready to build flexible queries? Start exploring! 🚀

Released under the MIT License.