Overview
ThecreateTypedClient function creates a lightweight, type-safe GraphQL client using Genql. It features automatic request batching, a simpler API surface than Apollo Client, and is ideal for server-side environments or lightweight client applications.
Unlike createWellPlayedClient, this client:
- ✅ Automatically batches requests for better performance
- ✅ Provides a simple, type-safe query/mutation API
- ✅ Has a smaller bundle size
- ❌ Does not support GraphQL subscriptions
- ❌ Does not include caching capabilities
- ❌ Does not support Apollo-specific features
Function Signature
packages/typescript-sdk/src/typed-client.ts:6
Parameters
The organization ID to use for all requests. This header is sent with every GraphQL operation as
organization-id.The authentication token to use for the client. When provided, sent as
Bearer <token> in the Authorization header.Mutually exclusive with application - use either user token OR application credentials, not both.Application credentials for server-side authentication. The client will automatically obtain and refresh access tokens using OAuth client credentials flow.
The base URL environment to connect to.Examples:
"well-played.gg", "stg.well-played.gg"Default: "well-played.gg"Additional RequestInit options to pass to the underlying fetch calls.Common options include:
credentials:"include","same-origin", or"omit"mode:"cors","no-cors", or"same-origin"cache: Request cache moderedirect: Redirect handlingreferrer: Referrer URLsignal: AbortSignal for request cancellation
url, headers, batch, keepalive, method.Return Value
A typed GraphQL client instance with the following methods:
Request Batching
The typed client automatically batches requests that occur within the same batch window. This is configured by default with:- Multiple queries/mutations initiated within 100ms are combined into a single HTTP request
- Maximum 10 operations per batch
- Each operation still receives its individual response
- Reduces network overhead and improves performance
packages/typescript-sdk/src/typed-client.ts:22-25
Examples
Basic Client
Server-Side with Application Auth
Staging Environment
With Custom Fetch Options
Automatic Request Batching Example
Implementation Details
API Endpoints
The client constructs the GraphQL endpoint as:Header Management
Headers are set dynamically via an async function (defined intyped-client.ts:26-42):
- If
tokenis provided, use it directly - If
applicationcredentials are provided, obtain token via OAuth - Set
organization-idheader - Set
Authorization: Bearer <token>if token is available
HTTP Configuration
The client is configured with:- Method:
POST(all GraphQL operations) - Keepalive:
true(keeps connection alive for better performance) - Content-Type:
application/json
Related
- createWellPlayedClient - Full-featured Apollo Client with subscriptions and caching
- GraphQL Operations - Type-safe query construction using tagged templates