Overview
ThecreateWellPlayedClient function creates a fully configured Apollo Client instance for the WellPlayed GraphQL API. It supports queries, mutations, subscriptions (via WebSockets), SSR, application authentication, and advanced caching.
This client is ideal for React applications using Apollo hooks or any JavaScript environment requiring advanced GraphQL features.
Function Signature
packages/typescript-sdk/src/apollo.ts:80
Parameters
The organization ID to use for all requests. This header is sent with every GraphQL operation.
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.Type:
"well-played.gg" | "stg.well-played.gg"Default: "well-played.gg"Whether the client is running in Server-Side Rendering mode. When
true:- Disables local storage cache persistence
- Sets Apollo’s
ssrModeoption - Default:
false
The default fetch policy for queries and watch queries.Type: Apollo’s
FetchPolicy ("cache-first" | "cache-and-network" | "network-only" | "cache-only" | "no-cache" | "standby")Default: "network-only"Custom cache invalidation policies using @nerdwallet/apollo-cache-policies.
WebSocket configuration for GraphQL subscriptions.
Event handlers for errors and WebSocket lifecycle events.
Return Value
A configured Apollo Client instance ready to execute GraphQL operations. The client includes:
- HTTP link for queries and mutations
- WebSocket link for subscriptions (automatically selected based on operation type)
- Cache with invalidation policies
- Default error policies and fetch policies
Examples
Basic Client (Browser)
SSR Configuration (Next.js)
Application Authentication (Server)
With WebSocket Subscriptions
With Error Handling and Cache Configuration
Staging Environment
Implementation Details
API Endpoints
The client constructs the following URLs based onapiBaseUrl:
- GraphQL HTTP:
https://api.warrior.{apiBaseUrl}/graphql - GraphQL WebSocket:
wss://api.warrior.{apiBaseUrl}/graphql - OAuth:
https://oauth.warrior.{apiBaseUrl}
Cache Persistence
Whenssr: false (default), the client uses apollo3-cache-persist to synchronously persist the cache to localStorage. This provides offline-first capabilities and faster subsequent page loads.
Operation Routing
The client uses Apollo’ssplit to route operations:
- Subscriptions → WebSocket link
- Queries & Mutations → HTTP link
Related
- createTypedClient - Lightweight typed client with automatic batching
- GraphQL Operations - Type-safe query construction