Query Examples
This section provides practical examples of common GraphQL queries for the Intuition API.
Basic Queries
Fetching Atoms
query GetAtom($id: ID!) {
atom(id: $id) {
id
content
metadata {
title
author
createdAt
}
}
}
Fetching Triples
query GetTriples($subject: ID, $predicate: String, $object: ID) {
triples(subject: $subject, predicate: $predicate, object: $object) {
id
subject {
id
content
}
predicate
object {
id
content
}
metadata {
createdAt
confidence
}
}
}
Fetching Signals
query GetSignals($type: String, $limit: Int) {
signals(type: $type, limit: $limit) {
id
type
data
timestamp
source
}
}
Advanced Queries
Complex Filtering
query SearchAtoms($query: String!, $filters: AtomFilters) {
searchAtoms(query: $query, filters: $filters) {
id
content
metadata {
title
tags
createdAt
}
relevance
}
}
Pagination
query GetAtomsPaginated($first: Int, $after: String) {
atoms(first: $first, after: $after) {
edges {
node {
id
content
metadata {
title
createdAt
}
}
cursor
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
}
}
React Query Hooks
Using Generated Hooks
import { useGetAtomQuery } from '@0xintuition/graphql'
function AtomViewer({ atomId }: { atomId: string }) {
const { data, loading, error } = useGetAtomQuery({
variables: { id: atomId }
})
if (loading) return <div>Loading...</div>
if (error) return <div>Error: {error.message}</div>
return (
<div>
<h1>{data?.atom?.metadata?.title}</h1>
<p>{data?.atom?.content}</p>
</div>
)
}
Custom Hooks
import { useQuery } from '@tanstack/react-query'
import { getAtomDocument } from '@0xintuition/graphql'
function useCustomAtomQuery(atomId: string) {
return useQuery({
queryKey: ['atom', atomId],
queryFn: () => client.request(getAtomDocument, { id: atomId }),
enabled: !!atomId
})
}
Best Practices
- Use Fragments: Create reusable fragments for common fields
- Optimize Queries: Only request the fields you need
- Handle Errors: Always implement proper error handling
- Cache Strategically: Use React Query's caching capabilities
- Type Safety: Leverage generated types for better development experience
This page will be expanded with more query examples, advanced patterns, and real-world use cases.