1. Home
  2. Docs
  3. Engineering
  4. GraphQL
  5. Generate GraphQL Client SDKs

Generate GraphQL Client SDKs

Generate TypeScript Client SDKs using apollo-tooling

  1. Install apollo CLI as --dev into your Nx workspace (recommended by Apollo)
yarn add --dev apollo
  1. Create apollo.config.js in Nx app’s folder:
module.exports = {
  client: {
    service: {
      name: 'miluv-profile',
      url: 'http://localhost:3001/graphql',
      // optional headers
      headers: {
        //authorization: 'Bearer lkjfalkfjadkfjeopknavadf'
      // optional disable SSL validation check
      // skipSSLValidation: true
  1. Generate client

Tip: apollo client:codegen supports --watch to watch & auto-regenerate, which is useful during development.

apollo client:codegen -c apps/miluv-profile/apollo.config.js --endpoint=http://localhost:3001/graphql --target=typescript --includes=apps/miluv-profile/src/**/*.tsx


Files are generated alongside the React .tsx files inside __generated__ subfolders.

  1. Optional: Download the schema, NestJS/Strapi backend must be running:
# from workspace folder
apollo client:download-schema --endpoint=http://localhost:1337/graphql ./schema.graphql.json

Generate Kotlin/Java GraphQL Client SDK

If you use Gradle, you can use Apollo Client:
Required: schema.json

However, if you use Maven, use graphql-kotlin instead.

Maven pom.xml:

            <!-- GraphQL Client Generator -->
                            <!-- Enable only when needed -->
            <!-- build helper plugin is required for IntelliJ IDEA to correctly identify generated sources -->
  1. Ensure miluv-profile is running in http://localhost:3001/graphql
  2. Run: mvn compile -DskipTests

The generated sources will be in target/generated-sources/graphql

Download Apollo GraphQL Schema

  1. Install apollo CLI as --dev into your Nx workspace (recommended by Apollo)
yarn add --dev apollo

Add into your workspace.json, inside projects > miluv-profile > architect:

        "schema-download": {
          "builder": "@nrwl/workspace:run-commands",
          "options": {
            "commands": [
                "command": "node_modules/.bin/apollo service:download -c apps/miluv-profile/apollo.config.js --endpoint=http://localhost:3001/graphql apps/miluv-profile/schema.json"

Then run:

nx run miluv-profile:schema-download

How can we help?

Leave a Reply

Your email address will not be published. Required fields are marked *