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_ESMfixUse import syntax or dynamic import().
affects: >=1.0.0
gotchagenerate() is a named export — default import will be undefinedfixUse import { generate } from 'graphql-auto-query'. affects: >=1.0.0
breakingThe output format may change between minor versions — do not depend on specific formattingfixAlways 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.
fixUse import { generate } from 'graphql-auto-query'. generate is not a function
Default import used instead of named import.
fixUse 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.
fixEnsure 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.
fixPass an object with a schema property: generate({ schema }). Audit
Dependencies
graphqlrequiredParsing and building GraphQL schemas