Registry / http-networking / gotql
library2.2.0jsnpmunverified

GotQL v2.2.0 is a Node.js library that allows you to write GraphQL queries as JavaScript objects instead of strings, wrapping the Got HTTP client. It acts as a transpiler, converting JSON query definitions into proper GraphQL strings and sending them via HTTP. Key differentiators include built-in HTTP client (Got v11+), support for fragments, variables, enums via template literal helper, and nested fields. Release cadence: infrequent, last release Apr 2022. Requires Node >=18 and ESM.

npm install gotql
INSTALL
IMPORT
SIG · GOTQL
G
gotql
http-networkingjavascriptv2.2.0
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.

default
import gotql from 'gotql'
const gotql = require('gotql')
ESM-only since v2.2.0, no default export in CJS
query
import { query } from 'gotql'
const { query } = require('gotql')
Named export, works in ESM only
mutation
import { mutation } from 'gotql'
import mutation from 'gotql'
Named export, not default

Shows basic usage with ESM import, constructing a JSON query object and using the query() function with an authorization header.

import gotql from 'gotql'; const query = { operation: { name: 'users', fields: ['id', 'name', 'email'] } }; const options = { headers: { Authorization: `Bearer ${process.env.API_KEY ?? ''}` } }; try { const response = await gotql.query('https://api.example.com/graphql', query, options); console.log(response.data); } catch (err) { console.error(err); }
Debug
Known issues
breakingESM-only since v2.2.0; require() will fail with ERR_REQUIRE_ESM
fix
Use import instead of require, or downgrade to v2.0.8 if CJS required
affects: >=2.2.0
gotchaModifying the query object after passing to query() may cause unexpected behavior due to mutation
fix
Create a new object or deep clone before modifying
affects: *
deprecatedGot v11 is used; older Got v10 options may not work
fix
Refer to Got v11 documentation for options like http2, timeout, etc.
affects: >=2.2.0
gotchaArray arguments with more than one item may cause issues prior to v2.0.8
fix
Upgrade to v2.0.8 or later
affects: <2.0.8
gotchaFalsy variables (0, false, null) treated as undefined prior to v2.0.5
fix
Upgrade to v2.0.5 or later
affects: <2.0.5
Errors
Common errors & fixes
ERR_REQUIRE_ESM: require() of ES Module /path/to/node_modules/gotql/index.js from /path/to/yourfile.js not supported.
GotQL v2.2.0 is ESM-only, but you are using require()
fix
Switch to import syntax: import gotql from 'gotql'
TypeError: gotql.query is not a function
Using default import with CJS require; the module is ESM
fix
Use import gotql from 'gotql' or destructure: import { query } from 'gotql'
Error: Invalid query: "operation" field required
Query object is missing the operation property or it's malformed
fix
Ensure query object has structure: { operation: { name: 'operationName', fields: [...] } }
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies
gotrequiredHTTP client for making GraphQL requests
Agent activity
6 hits · last 30 days
node
6
Resources
gotql — npm install gotql · libregistry