Schema Reference
The Intuition GraphQL API is powered by Hasura, providing a rich set of features for querying and manipulating data.
Getting the Schemaβ
Generate the GraphQL schema via introspection:
# Mainnet
npx get-graphql-schema https://mainnet.intuition.sh/v1/graphql > schema.graphql
# Testnet
npx get-graphql-schema https://testnet.intuition.sh/v1/graphql > schema.graphql
This schema file can be used with code generation tools to create type-safe clients.
Filtering with where Clausesβ
Use boolean expressions to filter query results:
query GetRecentPersonAtoms {
atoms(
where: {
created_at: { _gte: "2024-01-01" }
type: { _eq: Person }
}
limit: 10
) {
term_id
label
created_at
}
}
Available Operatorsβ
Equality:
_eq- Equal to_neq- Not equal to
Comparisons:
_gt- Greater than_gte- Greater than or equal to_lt- Less than_lte- Less than or equal to
Array Operations:
_in- Value in array_nin- Value not in array
Pattern Matching:
_like- Pattern match (case-sensitive)_ilike- Pattern match (case-insensitive)
Null Checks:
_is_null- Check if null
Boolean Logic:
_and- Logical AND_or- Logical OR_not- Logical NOT
Combining Filtersβ
query ComplexFilter {
atoms(
where: {
_and: [
{ type: { _eq: Person } }
{
_or: [
{ label: { _ilike: "%ethereum%" } }
{ label: { _ilike: "%bitcoin%" } }
]
}
]
}
) {
term_id
label
}
}
Sorting with order_byβ
Sort results by one or more fields:
query GetTopAtoms {
atoms(
order_by: [
{ term: { total_market_cap: desc } }
{ created_at: desc }
]
limit: 10
) {
term_id
label
created_at
}
}
Sort directions:
asc- Ascending orderdesc- Descending orderasc_nulls_first- Ascending, nulls firstasc_nulls_last- Ascending, nulls lastdesc_nulls_first- Descending, nulls firstdesc_nulls_last- Descending, nulls last
Paginationβ
Offset-Based Paginationβ
Use limit and offset for offset-based pagination:
query GetAtomsPage($limit: Int!, $offset: Int!) {
atoms(
limit: $limit
offset: $offset
order_by: { created_at: desc }
) {
term_id
label
created_at
}
atoms_aggregate {
aggregate {
count
}
}
}
Variables:
{
"limit": 20,
"offset": 40
}
This fetches page 3 (items 41-60) when using 20 items per page.
Best practices:
- Always include
order_byfor consistent pagination - Fetch total count using
_aggregatefor pagination UI - Use reasonable limits (10-100 items per page)
Aggregationsβ
Compute statistics without fetching all nodes:
query GetPositionStats($accountId: String!) {
positions_aggregate(where: { account_id: { _eq: $accountId } }) {
aggregate {
count
sum {
shares
}
avg {
shares
}
min {
shares
}
max {
shares
}
stddev {
shares
}
variance {
shares
}
}
}
}
Available Aggregate Functionsβ
Count Operations:
count- Total number of rows
Numeric Aggregations:
sum- Sum of valuesavg- Average valuemin- Minimum valuemax- Maximum value
Statistical Functions:
stddev- Standard deviationstddev_pop- Population standard deviationstddev_samp- Sample standard deviationvariance- Variancevar_pop- Population variancevar_samp- Sample variance
Combining Aggregates with Nodesβ
query GetPositionsWithStats($accountId: String!, $limit: Int!) {
stats: positions_aggregate(where: { account_id: { _eq: $accountId } }) {
aggregate {
count
sum { shares }
}
}
positions(
where: { account_id: { _eq: $accountId } }
limit: $limit
order_by: { shares: desc }
) {
id
shares
}
}
Relationshipsβ
Navigate the knowledge graph through nested queries:
query GetAtomWithCreator($id: String!) {
atom(term_id: $id) {
term_id
label
creator {
id
label
image
}
term {
vaults(where: { curve_id: { _eq: "1" } }) {
total_shares
current_share_price
}
}
}
}
Key relationships:
- Atoms β Creator (account)
- Atoms β Term β Vaults
- Triples β Subject/Predicate/Object (atoms)
- Triples β Term β Vaults
- Vaults β Positions
- Positions β Account
- Positions β Vault
Primary Key Lookupsβ
Direct lookups by primary key are the most efficient:
query GetAtom($id: String!) {
atom(term_id: $id) { # Direct lookup by primary key
term_id
label
}
}
Primary keys by entity:
atom(term_id: String!)- Single atomtriple(term_id: String!)- Single tripleaccount(id: String!)- Single accountvault(term_id: String!, curve_id: numeric!)- Single vault (composite key)position(id: String!)- Single position
Distinct Valuesβ
Get distinct values for a field:
query GetDistinctAtomTypes {
atoms(distinct_on: [type]) {
type
}
}
Fragmentsβ
Reuse field selections across queries:
fragment AtomBasics on atoms {
term_id
label
image
type
creator {
id
label
}
}
query GetTriple($id: String!) {
triple(term_id: $id) {
term_id
subject {
...AtomBasics
}
predicate {
...AtomBasics
}
object {
...AtomBasics
}
}
}
Variablesβ
Always use variables for dynamic values:
query GetAtomsByType($type: atom_type!, $limit: Int!) {
atoms(
where: { type: { _eq: $type } }
limit: $limit
) {
term_id
label
}
}
Variables:
{
"type": "Person",
"limit": 20
}
Schema Introspectionβ
Query the schema itself:
query IntrospectTypes {
__schema {
types {
name
kind
description
}
}
}
query IntrospectAtomType {
__type(name: "atoms") {
name
fields {
name
type {
name
kind
}
}
}
}
Code Generationβ
Use the schema with code generation tools:
JavaScript/TypeScript:
- GraphQL Code Generator - Generate TypeScript types and hooks
- Apollo CLI - Generate types for Apollo Client
Python:
- Ariadne Codegen - Generate Python types
- sgqlc - Generate Python client code
Go:
Rust:
- graphql-client - Typed queries in Rust
- cynic - Type-safe GraphQL client
Next Stepsβ
- Query Atoms - Learn atom query patterns
- Query Triples - Learn triple query patterns
- Best Practices - Optimize your queries