This version (v0.7) has not been published to npm yet.
Skip to content

Reference / @getenginex/sdk/query / createQueries

createQueries() ​

createQueries(client): CoreQueries

Creates the core query factories over a client: one per read method, with the same name and the same input as the method (q.wallet.getBalance(), q.wallet.listTransactions({ page })). Each call returns { queryKey, queryFn }, compatible with TanStack Query v5's useQuery/prefetchQuery/fetchQuery, without the SDK depending on it. It makes no request: call it once per client.

  • Reads without a session (config.*): key ['enginex', 'public', namespace, method, input?] and a staleTime of 5 minutes (the configuration rarely changes). No other read has a staleTime.
  • Player reads: key ['enginex', 'user', userId, namespace, method, input?], with the session's userId at the moment the factory is called. Without a session, the key uses 'anonymous' and the queryFn rejects with UNAUTHENTICATED without making a request; the same happens if the session changes user before the fetch. Call the factory again after login (the React adapter does this).
  • queryFn passes the context's signal on in options.signal: cancelling the query aborts the fetch.
  • input only goes in the key when given; no key contains a token or password.

Parameters ​

client ​

EnginexClient

The client returned by createEnginexClient.

Returns ​

CoreQueries

Example ​

ts
import { useQuery } from '@tanstack/react-query'
import { createQueries } from '@getenginex/sdk/query'

const q = createQueries(enginex)
const balance = useQuery({ ...q.wallet.getBalance(), refetchInterval: 10_000 })
await queryClient.prefetchQuery(q.config.get())

Throws ​

CONFIGURATION_ERROR if client has no session.get() (it is not an SDK client).