How do I access the GraphQL schema for code generation?

Last updated: July 14, 2025

Context

When using GraphQL code generation tools to generate typed client code from the Spacelift GraphQL schema, authentication is required to access the schema introspection endpoint.

Answer

To access the GraphQL schema for code generation, you need to include authentication using a JWT token in your codegen configuration. Here's how to configure it:

  1. Ensure you have a valid JWT token for authentication

  2. Update your codegen configuration to include the authorization header:


import { CodegenConfig } from '@graphql-codegen/cli';

const config: CodegenConfig = {
  schema: {
    [process.env.SPACELIFT_API_URL || 'https://example.app.spacelift.io/graphql']: {
      headers: {
        Authorization: `Bearer ${process.env.SPACELIFT_JWT_TOKEN}`,
      },
    },
  },
  // rest of your configuration
};

export default config;

Without the authentication header, you will receive an error like:

✖ Failed to load schema: Could not obtain introspection result, received the following as response; { data: {} }

For more information about the GraphQL API and authentication, please refer to our API documentation.

To identify the exact query or mutation being executed, we recommend checking the Network tab of your browser's developer tools while performing the action in the UI.