Registry / serialization / tiny-graphql-query-compiler

tiny-graphql-query-compiler

JSON →
library0.2.3jsnpmunverified

A JavaScript DSL for constructing GraphQL queries programmatically. v0.2.3 (pre-1.0, experimental). Converts a plain object representation into a valid GraphQL query string with support for arguments, variables, and fragment composition. Key differentiators: extremely lightweight (~1KB), no runtime GraphQL parser, TypeScript-first with full type inference for fields and arguments, and includes compileWithVariableValues for extracting both query and variable bindings. Ideal for codebases that need to dynamically generate queries without the overhead of graphql-tag or Apollo.

npm install tiny-graphql-query-compiler
INSTALL
IMPORT
SIG · TINY-GRAPHQL-QUERY
T
tiny-graphql-query-compiler
serializationjavascriptv0.2.3
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.

compile
import { compile } from 'tiny-graphql-query-compiler'
const compile = require('tiny-graphql-query-compiler').compile;
The library is ESM-only (no default export), so require() must use .compile property access—better to use ESM import.
Call
import { Call } from 'tiny-graphql-query-compiler'
Used to wrap a field call with arguments. Must be used inside a fields object.
Var
import { Var } from 'tiny-graphql-query-compiler'
import { Var } from 'tiny-graphql-query-compiler/Var';
Do not use a subpath import; Var is a named export from the main package.
compileWithVariableValues
import { compileWithVariableValues } from 'tiny-graphql-query-compiler'
import compileWithVariableValues from 'tiny-graphql-query-compiler';
It's a named export, not a default export.

Shows basic compile, arguments with Call and Var, and compileWithVariableValues for extracting query and variables.

import { compile, Call, Var, compileWithVariableValues } from 'tiny-graphql-query-compiler'; // Simple query const simpleQuery = compile({ type: 'query', fields: { hello: true } }); console.log(simpleQuery); // Output: query { hello } // Query with arguments and variables const { query, variables } = compileWithVariableValues({ type: 'query', fields: { user: Call( { id: Var({ type: 'ID!', value: '1' }) }, { name: true, email: true } ) } }); console.log(query); // Output: query ($id: ID!) { user(id: $id) { name email } } console.log(variables); // Output: { id: '1' }
Debug
Known issues
breakingPre-1.0 API may change without major version bump.
fix
Pin to a specific version and monitor changelog.
affects: >=0.1.0 <1.0.0
deprecatedSymbolic names for types (e.g., 'ID!') are string literals, not enums—this may change in future releases.
fix
Currently no fix; be prepared to update string literals if types are later represented as TypeScript enums.
affects: >=0.1.0
gotchaCall and Var must be imported explicitly; they are not exported as part of a default object.
fix
Use named imports: import { Call, Var } from 'tiny-graphql-query-compiler'.
affects: >=0.1.0
gotchaThe library does not validate the resulting GraphQL; it only generates the string. Syntax errors in the object will produce incorrect queries.
fix
Always test generated queries against a real GraphQL endpoint or use a validator like graphql-js.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: Call is not a function
Missing named import for Call.
fix
Ensure you import Call: import { Call } from 'tiny-graphql-query-compiler'.
SyntaxError: Cannot use import statement outside a module
The package is ESM-only and cannot be required() without transpilation.
fix
Use import syntax in an ESM context, or configure Node.js to treat the package as ESM (e.g., set type: 'module' in package.json).
ReferenceError: compile is not defined
Using default import instead of named import.
fix
Use: import { compile } from 'tiny-graphql-query-compiler' (not import compile from ...).
Upgrade
Version history
0.2.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
8
OpenAI (training)
4
Resources