This website covers our upcoming v3 alpha. For v2 docs, see our previous website.
API
Configuration

Configuration

We aim to minimize the necessity of this page, relying on auto-detection and interactive setup for most cases.

If you think your use case is possible without a configuration file, tell us on Discord or GitHub!

Where?

GQty looks for its configurations in these locations, stopping on the first one found:

  1. A gqty property in your package.json, or
  2. .gqtyrc in JSON or YAML format, or
  3. .gqtyrc.json, .gqtyrc.yaml, .gqtyrc.yml, .gqtyrc.js or .gqtyrc.cjs, or
  4. files above, but inside .config/, or
  5. A gqty.config.js or gqty.config.cjs CommonJS module exporting an object.

What?

introspections <object>

An object specifying additional information for introspection queries.

type Introspections = {
  [endpoint: string]: {
    headers?: Record<string, string>;
  };
};

For example, you may specify an authorization header like this:

package.json
{
  // ... other fields skipped for brevity
  "gqty": {
    "introspections": {
      "https://example.com/graphql": {
        "headers": {
          "authorization": "Bearer eyJhbGciOiJIUzI..."
        }
      }
    }
  }
}

destination <string>

Destination path for the generated client, can be overridden by the CLI option --client.

Defaults to ./gqty/index.ts

scalarTypes <object>

An object mapping custom GraphQL scalars to TypeScript types, for example:

{
  scalarTypes: {
    DateTime: "string",
  },
}

preImport <string>

Custom snippet prepended to the generated schema, useful for custom GraphQL scalars or custom types in TypeScript that depends on the generated schema.

react <boolean>

Includes a react client during code generation, this adds React hooks to the exports. Can be overridden by the --react flag.

Defaults to true if react is found in dependencies

subscriptions <boolean> | <string>

Includes a subscriptions client during code generation, required when using subscriptions in your code. Possible values are:

  1. graphql-ws - Uses graphql-ws as the subscriptions client.
  2. graphql-sse - Uses graphql-sse as the subscriptions client.
  3. true - Deprecated, equals to graphql-ws.

Defaults to graphql-ws if subscription types are found during introspection.

javascriptOutput <boolean>

Generate Javascript code instead of TypeScript.

Defaults to true if typescript is not found in dependencies.

enumsAsStrings <boolean>

Define enums as a string union instead of enums objects, cannot be used in tandem with enumsAsConst.

Defaults to false.

enumsAsConst <boolean>

Define enums as const types instead of enums objects, cannot be used in tandem with enumsAsStrings.

Defaults to false.

transformSchema <function>

Transform the GraphQL Schema before client generation.

export interface GenerateOptions {
  /**
   * Transform the GraphQL Schema before being used to generate the client
   */
  transformSchema?: (
    schema: GraphQLSchema,
    graphql_js: typeof graphql
  ) => Promise<GraphQLSchema> | GraphQLSchema;
}