---
title: Reads
description: Guide to read data using GraphQL queries in the Intuition API
url: https://docs.intuition.systems/docs/v1/graphql-api/reads
markdown_url: https://docs.intuition.systems/docs/v1/graphql-api/reads.md
version: V1
llms_index: https://docs.intuition.systems/docs/v1/llms.txt
---

## GraphQL API

Our GraphQL API provides a flexible and efficient way to interact with our atomic data structure system. Through this documentation, you'll learn how to query and manipulate atomic data using our GraphQL endpoints. To help you explore and test the API interactively, we've integrated Apollo Explorer sandbox environments throughout this documentation.

These interactive playgrounds allow you to experiment with queries in real-time, seeing exactly how the API responds to different inputs and parameters.

This documentation will be split into sections by primitive, such as `Atoms`, `Triples`, and so on.

We maintain a GraphQL SDK for our API that includes these queries with additional hooks for React developers to use directly in their apps. You can find it here: [https://github.com/0xIntuition/intuition-ts/tree/main/packages/graphql](https://github.com/0xIntuition/intuition-ts/tree/main/packages/graphql)

Our SDK utilizes GraphQL Codegen and Fragments, but for the sake of clarity and simplicity the query examples in the playgrounds won't utilize Fragments.

## Best Practices

1. **Use the SDK**: Leverage our GraphQL SDK for type-safe queries
2. **Optimize Queries**: Only request the fields you need
3. **Handle Loading States**: Always show loading indicators
4. **Implement Error Boundaries**: Catch and handle errors gracefully
5. **Use Pagination**: Implement proper pagination for large datasets
6. **Cache Strategically**: Use React Query's caching capabilities

## Backend Architecture Overview

This architecture diagram illustrates the data flow and integration stack for the Intuition backend. We ingest data from two primary RPC sources: our EthMultiVault contract and a ChainLinkOracle contract. This blockchain data is processed in a Docker environment indexed through Substreams, parsing and structuring the data into a PostgreSQL database.

Hasura then provides a GraphQL API layer on top of Postgres, enabling flexible data querying powering our app layers. This architecture provides efficient blockchain data indexing, reliable storage, and scalable API access. Our upcoming GraphQL SDK will further streamline the process for app developers looking to consume our data for building and extending the Intuition protocol.

## GraphQL Playground

The interactive Apollo Sandbox below lets you explore our GraphQL API in real-time. You can write and execute queries, inspect the schema, and see live responses from our API. We've set up this environment to help you get familiar with our data structure and available operations.

Try starting with some basic queries like fetching atoms or exploring relationship triples. Here's a query to get you started:

You can copy and paste the code snippet below into the sandbox above to view the results.

```graphql
query GetAtoms(
  $limit: Int
  $offset: Int
  $orderBy: [atoms_order_by!]
  $where: atoms_bool_exp
) {
  total: atoms_aggregate(where: $where) {
    aggregate {
      count
    }
  }
  atoms(limit: $limit, offset: $offset, order_by: $orderBy, where: $where) {
    # Basic metadata
    term_id
    data
    image
    label
    emoji
    type
    wallet_id
    creator {
      id
      label
      image
    }

    # Transaction details
    block_number
    created_at
    updated_at
    transaction_hash
    creator_id

    # Vault details
    term {
      vaults(where: { curve_id: { _eq: "1" } }, order_by: { curve_id: asc }) {
        position_count
        total_shares
        current_share_price
        market_cap
        positions_aggregate {
          aggregate {
            count
            sum {
              shares
            }
          }
        }
        positions {
          id
          account {
            label
            id
          }
          shares
        }
      }
    }

    # Value metadata
    value {
      person {
        name
        image
        description
        url
      }
      thing {
        name
        image
        description
        url
      }
      organization {
        name
        image
        description
        url
      }
      account {
        id
        label
        image
      }
    }
  }
}
```

You can start with this initial `GetAtoms` query in the Apollo Sandbox or write your own. The schema Explorer (docs tab) on the left side of the sandbox shows all available queries, mutations, and types. As you type, you'll get real-time autocompletion and documentation hints to help you build your queries. You can then click the play button to see the response and then adjust your query as you explore our data.

Need inspiration? Check out the example queries in the GraphQL API Example Queries page to get started, or jump right in and start exploring!

## Query Examples

### GetAtoms

The `GetAtoms` query is the primary way to fetch atom data from the Intuition system. It provides comprehensive information about atoms including metadata, transaction details, and vault information.

```graphql
query GetAtoms(
  $limit: Int
  $offset: Int
  $orderBy: [atoms_order_by!]
  $where: atoms_bool_exp
) {
  total: atoms_aggregate(where: $where) {
    aggregate {
      count
    }
  }
  atoms(limit: $limit, offset: $offset, order_by: $orderBy, where: $where) {
    # Basic metadata
    term_id
    data
    image
    label
    emoji
    type
    wallet_id
    creator {
      id
      label
      image
    }

    # Transaction details
    block_number
    created_at
    updated_at
    transaction_hash
    creator_id

    # Vault details
    term {
      vaults(where: { curve_id: { _eq: "1" } }, order_by: { curve_id: asc }) {
        position_count
        total_shares
        current_share_price
        market_cap
        positions_aggregate {
          aggregate {
            count
            sum {
              shares
            }
          }
        }
        positions {
          id
          account {
            label
            id
          }
          shares
        }
      }
    }

    # Value metadata
    value {
      person {
        name
        image
        description
        url
      }
      thing {
        name
        image
        description
        url
      }
      organization {
        name
        image
        description
        url
      }
      account {
        id
        label
        image
      }
    }
  }
}
```

### GetAccounts

Query account information including balances and positions.

```graphql
query GetAccounts($limit: Int, $offset: Int) {
  accounts(limit: $limit, offset: $offset) {
    id
    label
    image
    positions {
      id
      shares
      vault {
        term_id
        curve_id
        current_share_price
        term {
          atom {
            label
            image
          }
        }
      }
    }
  }
}
```

### GetTriples

Fetch relationship triples between atoms.

```graphql
query GetTriples(
  $limit: Int
  $offset: Int
  $orderBy: [triples_order_by!]
  $where: triples_bool_exp
) {
  total: triples_aggregate(where: $where) {
    aggregate {
      count
    }
  }
  triples(limit: $limit, offset: $offset, order_by: $orderBy, where: $where) {
    term_id
    counter_term_id
    created_at
    subject {
      term_id
      label
      image
      data
      type
      value {
        thing {
          description
          url
        }
        person {
          description
          url
        }
        organization {
          description
          url
        }
      }
    }
    predicate {
      term_id
      label
      image
      data
      type
    }
    object {
      term_id
      label
      image
      data
      type
      value {
        thing {
          description
          url
        }
        person {
          description
          url
        }
        organization {
          description
          url
        }
      }
    }
    # Vault details for pro/counter positions
    term {
      vaults(where: { curve_id: { _eq: "2" } }) {
        total_shares
        current_share_price
        market_cap
        position_count
      }
    }
    counter_term {
      vaults(where: { curve_id: { _eq: "2" } }) {
        total_shares
        current_share_price
        market_cap
        position_count
      }
    }
  }
}
```

### GetPositions

Query user positions in atom vaults.

```graphql
query GetPositions(
  $limit: Int
  $offset: Int
  $orderBy: [positions_order_by!]
  $where: positions_bool_exp
) {
  total: positions_aggregate(where: $where) {
    aggregate {
      count
      sum {
        shares
      }
    }
  }
  positions(limit: $limit, offset: $offset, order_by: $orderBy, where: $where) {
    id
    created_at
    updated_at
    shares
    account {
      id
      label
      image
    }
    vault {
      created_at
      updated_at
      term {
        atom {
          term_id
          label
          image
          term {
            vaults(where: { curve_id: { _eq: "1" } }) {
              term_id
              total_shares
              current_share_price
              position_count
            }
          }
        }
        triple {
          term_id
          subject {
            term_id
            label
            image
          }
          predicate {
            term_id
            label
            image
          }
          object {
            term_id
            label
            image
          }
          term {
            vaults(where: { curve_id: { _eq: "2" } }) {
              market_cap
              current_share_price
              position_count
            }
          }
        }
      }
    }
  }
}
```

### GetVaults

Fetch vault information including share prices and positions.

```graphql
query GetVaults($limit: Int, $offset: Int) {
  vaults(limit: $limit, offset: $offset) {
    term_id
    curve_id
    term {
      atom {
        label
        image
      }
    }
    current_share_price
    total_shares
    position_count
    positions_aggregate {
      aggregate {
        count
        sum {
          shares
        }
      }
    }
  }
}
```

## Utilities

### Search and Filtering

```graphql
query SearchAtoms($query: String!, $limit: Int) {
  search_term(args: { query: $query }, limit: $limit) {
    id
    type
    atom {
      label
      image
      creator {
        id
        label
      }
    }
  }
}
```

### Pagination

Hasura uses offset-based pagination with `limit` and `offset`:

```graphql
query GetAtomsPaginated($limit: Int!, $offset: Int!) {
  atoms_aggregate {
    aggregate {
      count
    }
  }
  atoms(
    limit: $limit
    offset: $offset
    order_by: { created_at: desc }
  ) {
    term_id
    label
    image
    type
  }
}
```

## React Integration

### Using the GraphQL SDK

```tsx
import { useGetAtomsQuery } from '@0xintuition/graphql'

function AtomList() {
  const { data, loading, error } = useGetAtomsQuery({
    variables: {
      limit: 10,
      offset: 0
    }
  })

  if (loading) return <div>Loading...</div>
  if (error) return <div>Error: {error.message}</div>

  return (
    <div>
      {data?.atoms.map(atom => (
        <div key={atom.id}>
          <h3>{atom.label}</h3>
          <img src={atom.image} alt={atom.label} />
          <p>Type: {atom.type}</p>
        </div>
      ))}
    </div>
  )
}
```

*For more examples and advanced patterns, check out our [GraphQL SDK](https://github.com/0xIntuition/intuition-ts/tree/main/packages/graphql) and [Example Queries](https://docs.intuition.systems/docs/v1/graphql-api/examples/atom-with-vault) page.*
