# 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 |
|------|------|-------------|
| `useMachinesQuery` | Query | Computers enrolled for remote control, one row per database enrollment |
| `useMachineQuery` | Query | Computers enrolled for remote control, one row per database enrollment |
| `useCreateMachineMutation` | Mutation | Computers enrolled for remote control, one row per database enrollment |
| `useUpdateMachineMutation` | Mutation | Computers enrolled for remote control, one row per database enrollment |
| `useDeleteMachineMutation` | Mutation | Computers enrolled for remote control, one row per database enrollment |
| `useMachineMessagesQuery` | Query | Partitioned append-only ledger of session input, output and lifecycle |
| `useMachineMessageQuery` | Query | Partitioned append-only ledger of session input, output and lifecycle |
| `useCreateMachineMessageMutation` | Mutation | Partitioned append-only ledger of session input, output and lifecycle |
| `useUpdateMachineMessageMutation` | Mutation | Partitioned append-only ledger of session input, output and lifecycle |
| `useDeleteMachineMessageMutation` | Mutation | Partitioned append-only ledger of session input, output and lifecycle |
| `useMachineSessionsQuery` | Query | Command or terminal sessions running on an enrolled machine |
| `useMachineSessionQuery` | Query | Command or terminal sessions running on an enrolled machine |
| `useCreateMachineSessionMutation` | Mutation | Command or terminal sessions running on an enrolled machine |
| `useUpdateMachineSessionMutation` | Mutation | Command or terminal sessions running on an enrolled machine |
| `useDeleteMachineSessionMutation` | Mutation | Command or terminal sessions running on an enrolled machine |
| `useCurrentDatabaseIdQuery` | Query | currentDatabaseId |
| `useMachinesEnrollMutation` | Mutation | machinesEnroll |
| `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. |
## Table Hooks
### Machine
```typescript
// List all machines
const { data, isLoading } = useMachinesQuery({
selection: { fields: { createdAt: true, createdBy: true, createdByPrincipal: true, entityId: true, facts: true, id: true, isShared: true, label: true, lastSeenAt: true, ownerId: true, policy: true, principalId: true, relayUrl: true, revokedAt: true, tokenHash: true, updatedAt: true, updatedBy: true, updatedByPrincipal: true } },
});
// Get one machine
const { data: item } = useMachineQuery({
id: '',
selection: { fields: { createdAt: true, createdBy: true, createdByPrincipal: true, entityId: true, facts: true, id: true, isShared: true, label: true, lastSeenAt: true, ownerId: true, policy: true, principalId: true, relayUrl: true, revokedAt: true, tokenHash: true, updatedAt: true, updatedBy: true, updatedByPrincipal: true } },
});
// Create a machine
const { mutate: create } = useCreateMachineMutation({
selection: { fields: { id: true } },
});
create({ createdBy: '', createdByPrincipal: '', entityId: '', facts: '', isShared: '', label: '', lastSeenAt: '', ownerId: '', policy: '', principalId: '', relayUrl: '', revokedAt: '', tokenHash: '', updatedBy: '', updatedByPrincipal: '' });
```
### MachineMessage
```typescript
// List all machineMessages
const { data, isLoading } = useMachineMessagesQuery({
selection: { fields: { actorId: true, content: true, createdByPrincipal: true, entityId: true, id: true, kind: true, ownerId: true, recordedAt: true, seq: true, sessionId: true } },
});
// Get one machineMessage
const { data: item } = useMachineMessageQuery({
id: '',
selection: { fields: { actorId: true, content: true, createdByPrincipal: true, entityId: true, id: true, kind: true, ownerId: true, recordedAt: true, seq: true, sessionId: true } },
});
// Create a machineMessage
const { mutate: create } = useCreateMachineMessageMutation({
selection: { fields: { id: true } },
});
create({ actorId: '', content: '', createdByPrincipal: '', entityId: '', kind: '', ownerId: '', recordedAt: '', seq: '', sessionId: '' });
```
### MachineSession
```typescript
// List all machineSessions
const { data, isLoading } = useMachineSessionsQuery({
selection: { fields: { agentMode: true, agentSessionRef: true, args: true, cols: true, command: true, createdAt: true, createdBy: true, createdByPrincipal: true, cwd: true, endedAt: true, entityId: true, env: true, exitCode: true, id: true, interactive: true, lastActivityAt: true, lastSeq: true, machineId: true, metadata: true, ownerId: true, pid: true, runId: true, startedAt: true, state: true, termRows: true, updatedAt: true, updatedBy: true, updatedByPrincipal: true } },
});
// Get one machineSession
const { data: item } = useMachineSessionQuery({
id: '',
selection: { fields: { agentMode: true, agentSessionRef: true, args: true, cols: true, command: true, createdAt: true, createdBy: true, createdByPrincipal: true, cwd: true, endedAt: true, entityId: true, env: true, exitCode: true, id: true, interactive: true, lastActivityAt: true, lastSeq: true, machineId: true, metadata: true, ownerId: true, pid: true, runId: true, startedAt: true, state: true, termRows: true, updatedAt: true, updatedBy: true, updatedByPrincipal: true } },
});
// Create a machineSession
const { mutate: create } = useCreateMachineSessionMutation({
selection: { fields: { id: true } },
});
create({ agentMode: '', agentSessionRef: '', args: '', cols: '', command: '', createdBy: '', createdByPrincipal: '', cwd: '', endedAt: '', entityId: '', env: '', exitCode: '', interactive: '', lastActivityAt: '', lastSeq: '', machineId: '', metadata: '', ownerId: '', pid: '', runId: '', startedAt: '', state: '', termRows: '', updatedBy: '', updatedByPrincipal: '' });
```
## Custom Operation Hooks
### `useCurrentDatabaseIdQuery`
currentDatabaseId
- **Type:** query
- **Arguments:** none
### `useMachinesEnrollMutation`
machinesEnroll
- **Type:** mutation
- **Arguments:**
| Argument | Type |
|----------|------|
| `input` | MachinesEnrollInput (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) |