# Graphql SDK

## Installation <a href="#installation" id="installation"></a>

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

```bash
bun add @inverter-network/graphql
```

***

## Initializing the Graphql SDK <a href="#initializing-the-sdk" id="initializing-the-sdk"></a>

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

<pre class="language-typescript"><code class="lang-typescript">import { Client } from '@inverter-network/graphql'

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

<strong>Client.updateUrl(devUrl) // By default the Client uses `prodUrl`
</strong></code></pre>

***

## 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.

{% code overflow="wrap" %}

```typescript
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)
})
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.inverter.network/sdk/graphql-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
