# 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 %}
