Getting started with GraphQL-Sdk-Generator
Last updated
Last updated
GraphQL SDK generator translates GraphQL Schema to Javascript, Typescript code enabling you to get smooth auto completion and validation for your GraphQL Schema,
First install the required package from npm(we will use as a sample example). GraphQL SDK Generator is a standalone package. Once you generate the code, you don't need the package anymore, so it is recommended to install it globally.
Then will create a config.json file with the following contents.
Then run the graphql-sdk-generator command to generate the client inside a directory by passing path of config file using -c
Once the code is generated, you need to install additional dependencies to run the generated code. These dependencies are necessary for making requests using the generated SDK
The generated client exposes a getSdk
function. To use it, initialize a GraphQLClient
, pass custom headers if necessary, and pass the client to getSdk
to send requests.
Currently we don't support the following features (some features are planned in future)
Custom naming for mutations, queries, variables
Allow to create multiple clients in one folder
Batching requests
GraphQL SDK generator will only work for and is not tested for below versions.
All the errors generated by client is handled by a custom error handler which you add in your codebase by seeing this .
We cannot pass a custom fetch client as the script is highly dependent on