An open API service indexing awesome lists of open source software.

https://github.com/node-libraries/pothos-query-generator

Plugin to output 'query.graphql' from pothos to file
https://github.com/node-libraries/pothos-query-generator

Last synced: about 2 months ago
JSON representation

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

Awesome Lists containing this project

README

          

# pothos-query-generator

[![](https://img.shields.io/npm/l/pothos-query-generator)](https://www.npmjs.com/package/pothos-query-generator)
[![](https://img.shields.io/npm/v/pothos-query-generator)](https://www.npmjs.com/package/pothos-query-generator)
[![](https://img.shields.io/npm/dw/pothos-query-generator)](https://www.npmjs.com/package/pothos-query-generator)
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/node-libraries/pothos-query-generator)

A plugin for [Pothos](https://pothos-graphql.dev/) that automatically generates example GraphQL queries using [graphql-auto-query](https://github.com/SoraKumo001/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.

```ts
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.

```ts
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