{"id":26479,"library":"tiny-graphql-query-compiler","title":"tiny-graphql-query-compiler","description":"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.","status":"active","version":"0.2.3","language":"javascript","source_language":"en","source_url":"https://github.com/gadget-inc/js-clients","tags":["javascript","typescript"],"install":[{"cmd":"npm install tiny-graphql-query-compiler","lang":"bash","label":"npm"},{"cmd":"yarn add tiny-graphql-query-compiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add tiny-graphql-query-compiler","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library is ESM-only (no default export), so require() must use .compile property access—better to use ESM import.","wrong":"const compile = require('tiny-graphql-query-compiler').compile;","symbol":"compile","correct":"import { compile } from 'tiny-graphql-query-compiler'"},{"note":"Used to wrap a field call with arguments. Must be used inside a fields object.","symbol":"Call","correct":"import { Call } from 'tiny-graphql-query-compiler'"},{"note":"Do not use a subpath import; Var is a named export from the main package.","wrong":"import { Var } from 'tiny-graphql-query-compiler/Var';","symbol":"Var","correct":"import { Var } from 'tiny-graphql-query-compiler'"},{"note":"It's a named export, not a default export.","wrong":"import compileWithVariableValues from 'tiny-graphql-query-compiler';","symbol":"compileWithVariableValues","correct":"import { compileWithVariableValues } from 'tiny-graphql-query-compiler'"}],"quickstart":{"code":"import { compile, Call, Var, compileWithVariableValues } from 'tiny-graphql-query-compiler';\n\n// Simple query\nconst simpleQuery = compile({\n  type: 'query',\n  fields: {\n    hello: true\n  }\n});\nconsole.log(simpleQuery);\n// Output: query { hello }\n\n// Query with arguments and variables\nconst { query, variables } = compileWithVariableValues({\n  type: 'query',\n  fields: {\n    user: Call(\n      { id: Var({ type: 'ID!', value: '1' }) },\n      {\n        name: true,\n        email: true\n      }\n    )\n  }\n});\nconsole.log(query);\n// Output: query ($id: ID!) { user(id: $id) { name email } }\nconsole.log(variables);\n// Output: { id: '1' }","lang":"typescript","description":"Shows basic compile, arguments with Call and Var, and compileWithVariableValues for extracting query and variables."},"warnings":[{"fix":"Pin to a specific version and monitor changelog.","message":"Pre-1.0 API may change without major version bump.","severity":"breaking","affected_versions":">=0.1.0 <1.0.0"},{"fix":"Currently no fix; be prepared to update string literals if types are later represented as TypeScript enums.","message":"Symbolic names for types (e.g., 'ID!') are string literals, not enums—this may change in future releases.","severity":"deprecated","affected_versions":">=0.1.0"},{"fix":"Use named imports: import { Call, Var } from 'tiny-graphql-query-compiler'.","message":"Call and Var must be imported explicitly; they are not exported as part of a default object.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Always test generated queries against a real GraphQL endpoint or use a validator like graphql-js.","message":"The library does not validate the resulting GraphQL; it only generates the string. Syntax errors in the object will produce incorrect queries.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure you import Call: import { Call } from 'tiny-graphql-query-compiler'.","cause":"Missing named import for Call.","error":"TypeError: Call is not a function"},{"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).","cause":"The package is ESM-only and cannot be required() without transpilation.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Use: import { compile } from 'tiny-graphql-query-compiler' (not import compile from ...).","cause":"Using default import instead of named import.","error":"ReferenceError: compile is not defined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}