Registry / testing / graphql-auto-query

graphql-auto-query

JSON →
library1.1.1jsnpmunverified

Automatic generation of GraphQL queries, mutations, and subscriptions from GraphQL schemas. v1.1.1 (stable) — generates comprehensive query documents for testing and introspection. Supports both local .graphql files and remote endpoints via introspection. Differentiates from similar tools by offering granular depth control per operation type (query, mutation, subscription) and a dual CLI/library interface. Ships TypeScript types.

npm install graphql-auto-query
INSTALL
IMPORT
SIG · GRAPHQL-AUTO-QUERY
G
graphql-auto-query
testingjavascriptv1.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

generate
import { generate } from 'graphql-auto-query'
const { generate } = require('graphql-auto-query')
ESM-only; CommonJS require will fail
generate
import { generate } from 'graphql-auto-query'
import generate from 'graphql-auto-query'
Not a default export; use named import
type GenerateOptions
import type { GenerateOptions } from 'graphql-auto-query'
Type import for TypeScript users

Shows programmatic usage: reading a schema, generating queries, and writing output with depth control.

import fs from 'fs'; import { generate } from 'graphql-auto-query'; // Read schema from file const schema = fs.readFileSync('schema.graphql', 'utf-8'); // Generate queries with default depth 2 const result = generate({ schema }); console.log(result); // Generate with custom depths const resultCustom = generate({ schema, depth: 3, queryDepth: 4, mutationDepth: 2 }); // Write output to file fs.writeFileSync('query.graphql', resultCustom, 'utf-8');
Debug
Known issues
gotchaESM-only package — using require() will throw ERR_REQUIRE_ESM
fix
Use import syntax or dynamic import().
affects: >=1.0.0
gotchagenerate() is a named export — default import will be undefined
fix
Use import { generate } from 'graphql-auto-query'.
affects: >=1.0.0
breakingThe output format may change between minor versions — do not depend on specific formatting
fix
Always test output when upgrading.
affects: >=1.0.0
deprecatedNo deprecation warnings as of v1.1.1
Errors
Common errors & fixes
const { generate } = require('graphql-auto-query'); Error [ERR_REQUIRE_ESM]
Package is ESM-only, not CJS.
fix
Use import { generate } from 'graphql-auto-query'.
generate is not a function
Default import used instead of named import.
fix
Use import { generate } from 'graphql-auto-query' instead of import generate from 'graphql-auto-query'.
ENOENT: no such file or directory, open 'schema.graphql'
The schema file path is incorrect.
fix
Ensure the file exists at the specified path or use an absolute path.
Cannot read properties of undefined (reading 'schema')
Calling generate() with no options object.
fix
Pass an object with a schema property: generate({ schema }).
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
graphqlrequiredParsing and building GraphQL schemas
Agent activity
6 hits · last 30 days
node
6
Resources
graphql-auto-query — npm install graphql-auto-query · libregistry