Skip to main content

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 order
  • desc - Descending order
  • asc_nulls_first - Ascending, nulls first
  • asc_nulls_last - Ascending, nulls last
  • desc_nulls_first - Descending, nulls first
  • desc_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_by for consistent pagination
  • Fetch total count using _aggregate for 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 values
  • avg - Average value
  • min - Minimum value
  • max - Maximum value

Statistical Functions:

  • stddev - Standard deviation
  • stddev_pop - Population standard deviation
  • stddev_samp - Sample standard deviation
  • variance - Variance
  • var_pop - Population variance
  • var_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 atom
  • triple(term_id: String!) - Single triple
  • account(id: String!) - Single account
  • vault(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:

Python:

Go:

  • gqlgen - Generate Go server and client code
  • genqlient - Generate Go client code

Rust:

Complete Entity Reference​

The Intuition GraphQL API exposes 142 root query fields. Every table/view supports standard Hasura operations: list queries with where/order_by/limit/offset, _aggregate queries, and _stream subscriptions.

Core Entities​

EntityPrimary KeyDescriptionDocs
atomsterm_idFundamental units of knowledgeQueries
triplesterm_idSubject-predicate-object relationshipsQueries
accountsidUser accounts and walletsQueries
termsidShared term data for atoms and triples (holds total_assets, total_market_cap, type)
vaultsterm_id, curve_idBonding curve vaults for stakingQueries
positionsidUser stakes in vaultsQueries

Atom Value Types​

EntityPrimary KeyDescription
atom_valuesidUnion of all atom value types
personsidPerson atom values
thingsidThing atom values
organizationsidOrganization atom values
text_objectsidText atom values
json_objectsidJSON atom values
byte_objectidByte/binary atom values

Activity Entities​

EntityPrimary KeyDescriptionDocs
signalsβ€”Enriched deposit/redemption eventsQueries
eventsidRaw blockchain eventsQueries
depositsidDeposit transactionsQueries
redemptionsidRedemption transactionsQueries

Position Tracking Views​

EntityPrimary KeyDescriptionDocs
positions_with_valueβ€”Positions enriched with PnL, redeemable valueQueries
position_changesidIndividual position change eventsQueries
position_change_dailyβ€”Daily aggregated position changesQueries
position_change_hourlyβ€”Hourly aggregated position changesQueries

Graph Structure Views​

EntityPrimary KeyDescriptionDocs
subject_predicatessubject_id, predicate_idSubject-predicate pair aggregatesQueries
predicate_objectspredicate_id, object_idPredicate-object pair aggregatesQueries
triple_termterm_idTriple-term aggregate statsQueries
triple_vaultterm_id, curve_idTriple vault-level dataQueries

Statistics & Fees​

EntityPrimary KeyDescriptionDocs
statsidProtocol-wide statisticsQueries
statHoursidHourly protocol stats snapshots
fee_transfersidProtocol fee transfer eventsQueries
protocol_fee_accrualsidFee accruals by epochQueries

PnL & Leaderboard​

EntityPrimary KeyDescriptionDocs
pnl_leaderboard_entryβ€”Leaderboard rows (34 fields)Queries
pnl_leaderboard_statsβ€”Aggregate leaderboard statsQueries
account_pnl_rankβ€”Individual account rank/percentileQueries

Time-Series (Continuous Aggregates)​

Pre-computed at hourly, daily, weekly, and monthly granularities.

Base EntityIntervalsDescriptionDocs
share_price_change_stats_*hourly, daily, weekly, monthlyShare price OHLC-style statsQueries
signal_stats_*hourly, daily, weekly, monthlySignal count and volumeQueries
term_total_state_change_stats_*hourly, daily, weekly, monthlyTerm market cap changesQueries
term_total_state_changesβ€”Raw state change eventsQueries

Price & Share Data​

EntityPrimary KeyDescriptionDocs
share_price_changesβ€”Vault share price historyQueries
chainlink_pricesidChainlink oracle price data

Social​

EntityPrimary KeyDescriptionDocs
booksidBook entities
cached_imagesurlCached image data with moderation scores

Cross-Chain​

EntityPrimary KeyDescription
caip10idCAIP-10 cross-chain identifier mapping

Database Functions (SQL Functions Exposed as Queries)​

These functions take an args parameter with function-specific inputs and return standard Hasura-filterable results.

FunctionArgsReturnsDescriptionDocs
search_termsearch: Stringatoms[]Full-text search for atomsQueries
search_term_from_followingaddress: String, search: Stringatoms[]Search within followed accountsQueries
search_term_tsvectorsearch: Stringatoms[]Full-text search (tsvector variant)
search_positions_on_subjectaddresses: _text, search_fields: jsonbpositions[]Find positions on a subjectQueries
followingaddress: Stringaccounts[]Accounts followed by addressQueries
signals_from_followingaddress: Stringsignals[]Signals from followed accountsQueries
positions_from_followingaddress: Stringpositions[]Positions from followed accountsQueries
get_pnl_leaderboardp_limit, p_offset, p_sort_by, ...pnl_leaderboard_entry[]PnL leaderboardQueries
get_pnl_leaderboard_periodp_start_date, p_end_date, ...pnl_leaderboard_entry[]Period-scoped leaderboardQueries
get_pnl_leaderboard_statsp_term_id, p_time_filterpnl_leaderboard_stats[]Leaderboard aggregate statsQueries
get_vault_leaderboardp_term_id, p_curve_id, ...pnl_leaderboard_entry[]Vault leaderboardQueries
get_vault_leaderboard_periodp_start_date, p_end_date, ...pnl_leaderboard_entry[]Period-scoped vault leaderboardQueries
get_account_pnl_rankp_account_id, p_sort_by, ...account_pnl_rank[]Account rank + percentileQueries

Custom Operations (Hasura Actions)​

These are backed by external services (chart-api, IPFS gateway). They use camelCase naming and take a single typed input or named argument.

OperationTypeDescriptionDocs
getAccountPnlCurrentQueryCurrent account PnL snapshotQueries
getAccountPnlChartQueryAccount PnL over timeQueries
getAccountPnlRealizedQueryRealized PnL breakdownQueries
getPositionPnlChartQueryPosition-level PnL chartQueries
getChartJsonQueryChart data as JSONQueries
getChartRawJsonQueryRaw chart data as JSONQueries
getChartSvgQueryChart rendered as SVGQueries
getChartRawSvgQueryMinimal raw SVG chartQueries
pinThingMutationPin Thing metadata to IPFSMutations
pinPersonMutationPin Person metadata to IPFSMutations
pinOrganizationMutationPin Organization metadata to IPFSMutations
uploadImageMutationUpload image (base64)Mutations
uploadImageFromUrlMutationUpload image from URLMutations
uploadJsonToIpfsMutationUpload JSON to IPFSMutations

Next Steps​