feat(clients): OpenAPI-generated React Query hooks#152
Conversation
Add clients/react-query/ — a typed @tanstack/react-query client for the Wraith API. Request/response types are generated from openapi.json with openapi-typescript and the transport is openapi-fetch, so the hooks are fully typed end to end with no hand-maintained models. - Hooks for every list endpoint: useIncomingTransfers, useOutgoingTransfers, useAddressTransfers, useTransactionTransfers, useAccountSummary, useAccountTransfers, usePopularAssets, useNftTransfers, useWebhooks, useWebhookDeliveries, useHostFunctionLogs, useStatus. - createWraithClient + WraithClientProvider/useWraithClient wire a typed client through context; non-2xx responses reject with a typed WraithError. - Stable queryKeys factory for invalidation/prefetch. - npm run generate regenerates src/schema.d.ts from ../../openapi.json; a React Query SDK workflow regenerates in CI and fails on drift, then typechecks, tests, and builds. - vitest tests cover request shaping (path + query params), response parsing, and error mapping. Closes Miracle656#146
|
@Asheeyah23 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Miracle656
left a comment
There was a problem hiding this comment.
Clean, fully-isolated additive client (clients/react-query/, own package.json/lockfile/tsconfig — can't affect the main build). Types are generated from openapi.json via openapi-typescript + openapi-fetch (no hand-maintained models), with a drift-check workflow (git diff --exit-code after npm run generate) so it can't silently desync from the spec. Hooks for every list endpoint, typed WraithError on non-2xx, queryKeys factory for invalidation, 4 vitest passing. Mirrors clients/python/. Closes #146.
Closes #146
What
Adds
clients/react-query/— a typed@tanstack/react-queryclient for the Wraith API. Following the issue's suggestion (orvaloropenapi-fetch+ React Query), this usesopenapi-typescriptto generate the request/response types fromopenapi.jsonandopenapi-fetchfor transport, so every hook is fully typed end-to-end with no hand-maintained models. It mirrors the layout of the existingclients/python/.Acceptance criteria
src/hooks/:useIncomingTransfersGET /transfers/incoming/{address}useOutgoingTransfersGET /transfers/outgoing/{address}useAddressTransfersGET /transfers/address/{address}useTransactionTransfersGET /transfers/tx/{txHash}useAccountSummaryGET /accounts/{address}/summaryuseAccountTransfersGET /accounts/{address}/transfersusePopularAssetsGET /assets/popularuseNftTransfersGET /nfts/transfersuseWebhooksGET /webhooksuseWebhookDeliveriesGET /webhooks/{id}/deliveriesuseHostFunctionLogsGET /host-fn/{contractId}useStatusGET /statusnpm run generaterunsopenapi-typescript ../../openapi.json -o src/schema.d.ts. The new.github/workflows/react-query-sdk.ymlregenerates the schema and fails on drift (git diff --exit-code), then typechecks, tests, and builds — so the client can never silently fall out of sync with the spec.API
createWraithClient({ baseUrl })+<WraithClientProvider client={…}>wire a typed client through context; hooks read it viauseWraithClient(). Non-2xx responses reject with a typedWraithError(.status,.body). AqueryKeysfactory is exported for invalidation/prefetch.Verification
npm run generateis idempotent (no drift).tsc --noEmitclean;npm run buildemitsdist/.vitest run→ 4 passed: request shaping (path + query serialization), response parsing, collection endpoint without params, and non-2xx →WraithErrormapping.Note: the spec's transfer schema doesn't model an
isSacfield, so the typed hooks expose the fields the spec declares (amount,displayAmount, …); the generated types followopenapi.jsonexactly.