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
- Host: GitHub
- URL: https://github.com/node-libraries/pothos-query-generator
- Owner: node-libraries
- License: mit
- Created: 2023-10-10T01:46:59.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-10-10T01:53:38.000Z (over 2 years ago)
- Last Synced: 2025-06-15T11:07:27.049Z (12 months ago)
- Language: TypeScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pothos-query-generator
[](https://www.npmjs.com/package/pothos-query-generator)
[](https://www.npmjs.com/package/pothos-query-generator)
[](https://www.npmjs.com/package/pothos-query-generator)
[](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