# React Query Hooks
## Setup
```typescript
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { configure } from './hooks';
configure({
endpoint: 'https://api.example.com/graphql',
headers: { Authorization: 'Bearer ' },
});
const queryClient = new QueryClient();
function App() {
return (
);
}
```
## Hooks
| Hook | Type | Description |
|------|------|-------------|
| `useCommitsQuery` | Query | Commit history — each commit snapshots a tree root for a store |
| `useCommitQuery` | Query | Commit history — each commit snapshots a tree root for a store |
| `useCreateCommitMutation` | Mutation | Commit history — each commit snapshots a tree root for a store |
| `useUpdateCommitMutation` | Mutation | Commit history — each commit snapshots a tree root for a store |
| `useDeleteCommitMutation` | Mutation | Commit history — each commit snapshots a tree root for a store |
| `useGetAllTreeNodesQuery` | Query | List all getAllTreeNodes |
| `useObjectsQuery` | Query | Content-addressed Merkle tree objects keyed by UUID v5 hash of data + children |
| `useObjectQuery` | Query | Content-addressed Merkle tree objects keyed by UUID v5 hash of data + children |
| `useCreateObjectMutation` | Mutation | Content-addressed Merkle tree objects keyed by UUID v5 hash of data + children |
| `useUpdateObjectMutation` | Mutation | Content-addressed Merkle tree objects keyed by UUID v5 hash of data + children |
| `useDeleteObjectMutation` | Mutation | Content-addressed Merkle tree objects keyed by UUID v5 hash of data + children |
| `useRefsQuery` | Query | Branch heads — mutable pointers into the commit chain |
| `useRefQuery` | Query | Branch heads — mutable pointers into the commit chain |
| `useCreateRefMutation` | Mutation | Branch heads — mutable pointers into the commit chain |
| `useUpdateRefMutation` | Mutation | Branch heads — mutable pointers into the commit chain |
| `useDeleteRefMutation` | Mutation | Branch heads — mutable pointers into the commit chain |
| `useStoresQuery` | Query | Named stores — one per version-controlled tree (e.g. one graph, one definition set) |
| `useStoreQuery` | Query | Named stores — one per version-controlled tree (e.g. one graph, one definition set) |
| `useCreateStoreMutation` | Mutation | Named stores — one per version-controlled tree (e.g. one graph, one definition set) |
| `useUpdateStoreMutation` | Mutation | Named stores — one per version-controlled tree (e.g. one graph, one definition set) |
| `useDeleteStoreMutation` | Mutation | Named stores — one per version-controlled tree (e.g. one graph, one definition set) |
| `useInitEmptyRepoMutation` | Mutation | initEmptyRepo |
| `useInsertNodeAtPathMutation` | Mutation | insertNodeAtPath |
| `useInsertNodesAtPathsMutation` | Mutation | insertNodesAtPaths |
| `useProvisionBucketMutation` | Mutation | Reconcile an S3 bucket for a logical bucket in the database.
Records the request on the bucket row via RLS; the bucket's job
trigger then enqueues the same storage:provision_bucket job used on
INSERT, and repeated requests collapse into one pending job. This is
idempotent for an already-reconciled bucket; failures become GraphQL
errors. |
| `useSetAndCommitMutation` | Mutation | setAndCommit |
| `useSetDataAtPathMutation` | Mutation | setDataAtPath |
| `useSetManyAndCommitMutation` | Mutation | setManyAndCommit |
## Table Hooks
### Commit
```typescript
// List all commits
const { data, isLoading } = useCommitsQuery({
selection: { fields: { authorId: true, committerId: true, databaseId: true, date: true, id: true, message: true, parentIds: true, storeId: true, treeId: true } },
});
// Get one commit
const { data: item } = useCommitQuery({
id: '',
selection: { fields: { authorId: true, committerId: true, databaseId: true, date: true, id: true, message: true, parentIds: true, storeId: true, treeId: true } },
});
// Create a commit
const { mutate: create } = useCreateCommitMutation({
selection: { fields: { id: true } },
});
create({ authorId: '', committerId: '', databaseId: '', date: '', message: '', parentIds: '', storeId: '', treeId: '' });
```
### GetAllTreeNodesRecord
```typescript
// List all getAllTreeNodes
const { data, isLoading } = useGetAllTreeNodesQuery({
selection: { fields: { data: true, path: true } },
});
```
### Object
```typescript
// List all objects
const { data, isLoading } = useObjectsQuery({
selection: { fields: { createdAt: true, data: true, databaseId: true, id: true, kids: true, ktree: true } },
});
// Get one object
const { data: item } = useObjectQuery({
id: '',
selection: { fields: { createdAt: true, data: true, databaseId: true, id: true, kids: true, ktree: true } },
});
// Create a object
const { mutate: create } = useCreateObjectMutation({
selection: { fields: { id: true } },
});
create({ data: '', databaseId: '', kids: '', ktree: '' });
```
### Ref
```typescript
// List all refs
const { data, isLoading } = useRefsQuery({
selection: { fields: { commitId: true, databaseId: true, id: true, name: true, storeId: true } },
});
// Get one ref
const { data: item } = useRefQuery({
id: '',
selection: { fields: { commitId: true, databaseId: true, id: true, name: true, storeId: true } },
});
// Create a ref
const { mutate: create } = useCreateRefMutation({
selection: { fields: { id: true } },
});
create({ commitId: '', databaseId: '', name: '', storeId: '' });
```
### Store
```typescript
// List all stores
const { data, isLoading } = useStoresQuery({
selection: { fields: { createdAt: true, databaseId: true, hash: true, id: true, name: true } },
});
// Get one store
const { data: item } = useStoreQuery({
id: '',
selection: { fields: { createdAt: true, databaseId: true, hash: true, id: true, name: true } },
});
// Create a store
const { mutate: create } = useCreateStoreMutation({
selection: { fields: { id: true } },
});
create({ databaseId: '', hash: '', name: '' });
```
## Custom Operation Hooks
### `useInitEmptyRepoMutation`
initEmptyRepo
- **Type:** mutation
- **Arguments:**
| Argument | Type |
|----------|------|
| `input` | InitEmptyRepoInput (required) |
### `useInsertNodeAtPathMutation`
insertNodeAtPath
- **Type:** mutation
- **Arguments:**
| Argument | Type |
|----------|------|
| `input` | InsertNodeAtPathInput (required) |
### `useInsertNodesAtPathsMutation`
insertNodesAtPaths
- **Type:** mutation
- **Arguments:**
| Argument | Type |
|----------|------|
| `input` | InsertNodesAtPathsInput (required) |
### `useProvisionBucketMutation`
Reconcile an S3 bucket for a logical bucket in the database.
Records the request on the bucket row via RLS; the bucket's job
trigger then enqueues the same storage:provision_bucket job used on
INSERT, and repeated requests collapse into one pending job. This is
idempotent for an already-reconciled bucket; failures become GraphQL
errors.
- **Type:** mutation
- **Arguments:**
| Argument | Type |
|----------|------|
| `input` | ProvisionBucketInput (required) |
### `useSetAndCommitMutation`
setAndCommit
- **Type:** mutation
- **Arguments:**
| Argument | Type |
|----------|------|
| `input` | SetAndCommitInput (required) |
### `useSetDataAtPathMutation`
setDataAtPath
- **Type:** mutation
- **Arguments:**
| Argument | Type |
|----------|------|
| `input` | SetDataAtPathInput (required) |
### `useSetManyAndCommitMutation`
setManyAndCommit
- **Type:** mutation
- **Arguments:**
| Argument | Type |
|----------|------|
| `input` | SetManyAndCommitInput (required) |