This is the base implementation of the WunderGraph HTTP protocol in TypeScript that can be used on both browser and server environments. It's used as the base interface for the Web client, React and Next.js implementations.
Let's start by adding the WunderGraph TypeScript client generator to your project.
Create the client
createClient will return a fully typesafe client that can be used to execute operations.
The client can be configured with a custom baseURL.
You can use the client on server environments that don't have a build-in fetch implementation by using the customFetch configuration option.
Install node-fetch or any other fetch polyfill.
And add it to the client configuration.
If you target older browsers you will need a polyfill for fetch, AbortController, AbortSignal and possibly Promise.
Adding custom headers
Run a query
You can run subscriptions using
subscribeOnce, this will return the subscription response directly and will not setup a stream. This is useful for SSR purposes for example.
Almost all methods accept an AbortController instance that can be used to cancel the request.
Query and mutation errors are returned as a
GraphQLResponseError object. By default, the first error specifiy the error message but you can access all GraphQL errors through the
errors property. Network errors and non 2xx responses are returned as a
ResponseError object and contain the status code as
Methods that initiate a network request throw a
Error if the request fails to initiate or the response is not 2xx. You can be sure that the request was successful if the method doesn't throw an error.
- Subscriptions are not supported server side, but can be fetched using