Skip to content

About

Plugin to output 'query.graphql' from pothos to file

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

pothos-query-generator

Ask DeepWiki

A plugin for Pothos that automatically generates example GraphQL queries using graphql-auto-query.

This plugin hooks into the Pothos schema build process and outputs a file containing generated queries based on your schema definition.

Usage

Basic Setup

Add the plugin to your SchemaBuilder and configure the pothosQueryGenerator options.

import SchemaBuilder from "@pothos/core";
import PothosQueryGeneratorPlugin from "pothos-query-generator";

const builder = new SchemaBuilder({
  plugins: [PothosQueryGeneratorPlugin],
  pothosQueryGenerator: {
    // Path to the output file
    output: "query.graphql",
    // Optional: Depth of the generated queries (default depends on graphql-auto-query)
    depth: 2,
  },
});

// ... define your schema ...

builder.toSchema();

Conditional Output

You can conditionally disable the output by setting output to false, null, or undefined. This is useful for generating files only in development environments.

import path from "path";
import SchemaBuilder from "@pothos/core";
import PothosQueryGeneratorPlugin from "pothos-query-generator";

const builder = new SchemaBuilder({
  plugins: [PothosQueryGeneratorPlugin],
  pothosQueryGenerator: {
    output:
      process.env.NODE_ENV === "development"
        ? path.join(process.cwd(), "graphql", "query.graphql")
        : false,
  },
});

Options

Option Type Description
output string | null | false The file path where the generated queries will be saved. If falsy, no file is written.
depth number (Optional) The recursion depth for generating nested fields in the query.
queryDepth number (Optional) The recursion depth for generating nested fields in the query. (overrides depth)
mutationDepth number (Optional) The recursion depth for generating nested fields in the mutation.
subscriptionDepth number (Optional) The recursion depth for generating nested fields in the subscription.

License

MIT

About

Plugin to output 'query.graphql' from pothos to file

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages