@trackunit/server-graphql-client
v0.0.76
Published
Typed GraphQL client for server code.
Keywords
Readme
@trackunit/server-graphql-client
Typed GraphQL client for server code.
For more info and a full guide on Iris App SDK Development, please visit our Developer Hub.
Runtime usage
import { createServerGraphqlClient, operationNameUrlResolver } from "@trackunit/server-graphql-client";
const client = createServerGraphqlClient({
baseUrl: env.graphqlInternalUrl,
name: "ai-storage",
headers: { Authorization: authorizationHeader, "TU-PREVIEW": "*" },
timeoutMs: 5_000,
resolveUrl: operationNameUrlResolver,
logger: console,
});
const data = await client.request({ document: SomeDocument, variables: { id }, signal });Pass a generated TypedDocumentNode; its data and variable types are inferred without a
raw query string, separate operation name, or consumer response schema.
timeoutMssets a client-wide timeout; request-levelsignalsupports cancellation.fetchImplaccepts an injectedfetchimplementation for tests.loggeris optional and accepts theServerGraphqlClientLoggerinterface. When omitted, the client does not log.
Hono extensions calling Trackunit public GraphQL should use createTrackunitGraphqlClient from @trackunit/serverside-utils.
Testing
Import the mock fetch from the /testing entrypoint:
import { mockGraphqlFetch } from "@trackunit/server-graphql-client/testing";
const fetchImpl = mockGraphqlFetch([
mockForSomeQuery({ id: "1" }, { some: { field: "value" } }),
]);
const client = createServerGraphqlClient({ baseUrl, fetchImpl });mockGraphqlFetch accepts generated mockFor* responses and matches by operation name and variables.
Trackunit
This package was developed by Trackunit ApS. Trackunit is the leading SaaS-based IoT solution for the construction industry, offering an ecosystem of hardware, fleet management software & telematics.
