Graphql SDK

Installation

To install the Graphql SDK, use your preferred package manager from the command line. For example, if you use bun, execute the following command:

bun add @inverter-network/graphql

Initializing the Graphql SDK

@inverter-network/graphql utilizes a singleton class instance hence the main initialization is optionally updating the graphql endpoint.

import { Client } from '@inverter-network/graphql'

const devUrl = 'https://dev.indexer.inverter.network/v1/graphql'
const prodUrl = 'https://indexer.inverter.network/v1/graphql'

Client.updateUrl(devUrl) // By default the Client uses `prodUrl`

Subscribing and Querying

Both Subscription and Query utilizes the same fields object, all we have to do is import query or subscription functions from the package.

import { type GraphQLQueryArgs, query, subscription } from '@inverter-network/graphql'

const fields = {
  Token: {
    __args: {
      where: {
        address: {
          _eq: '0x961bB3932A7efAa9aDcc7409e1fea090479E8312',
        },
        chainId: {
          _eq: 1101,
        },
      },
    },
    chainId: 1,
    address: 1,
    name: 1,
    decimals: 1,
    symbol: 1,
    totalSupply: 1,
  },
} as const satisfies GraphQLQueryArgs

// Query
const tokens = await query(fields)

// Subscription
const sub = subscription(fields)

// You can add as many callbacks to a subscription
sub.addCallback((data) => {
  console.log(data)
})

Last updated