Registry / api-clients / nanographql

nanographql

JSON →
library2.0.0jsnpmunverified

Tiny GraphQL client library (2.0.0) that converts tagged template literals into executable query functions. Minimal implementation (~15 lines) with no dependencies, ideal for small projects or when avoiding heavy clients like Apollo. Last updated in 2018; stable but experimental status. Differentiates by extreme size and simplicity, but lacks advanced features like caching or subscriptions.

npm install nanographql
INSTALL
IMPORT
SIG · NANOGRAPHQL
N
nanographql
api-clientsjavascriptv2.0.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.

gql
import gql from 'nanographql'
const { gql } = require('nanographql')
Package has a default export only. CommonJS require works as shown in example.
query function
const query = gql`...`; const body = query({ var: val })
query('...') as a string
Use tagged template literal, not a string argument.
query result
gql`...`
gql(`...`)
Must use tagged template syntax without parentheses.

Shows creating a GraphQL query using tagged template literal and using it with fetch.

const gql = require('nanographql'); const query = gql` query($name: String!) { movie(name: $name) { releaseDate } } `; const fetch = require('node-fetch'); async function main() { const body = query({ name: 'Back to the Future' }); const res = await fetch('/query', { method: 'POST', body: JSON.stringify(body), headers: { 'Content-Type': 'application/json' } }); const json = await res.json(); console.log(json); } main().catch(console.error);
Debug
Known issues
deprecatedStability is experimental; API may change.
fix
Upgrade to v2 if using older version.
affects: <2.0.0
gotchaThe query function returns a plain object, not a string.
fix
Use JSON.stringify on the result before sending.
affects: >=1.0.0
gotchaNo built-in support for variables outside the tagged template; must pass them as function argument.
fix
Always call the query function with variables object.
affects: >=1.0.0
gotchaDoes not parse or validate GraphQL syntax; assumes valid input.
fix
Ensure your query strings are syntactically correct.
affects: >=1.0.0
gotchaNo support for fragments or directives beyond what's in the template.
fix
Inline fragments into the query string.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: gql is not a function
Using named import instead of default import.
fix
Use `const gql = require('nanographql')` instead of `const { gql } = require('nanographql')`.
Unexpected token: at position ...
Using parentheses instead of backticks for template literal.
fix
Write `gql`...`` (tagged template literal) instead of `gql('...')`.
Cannot convert object to string
Sending the query result directly without JSON.stringify.
fix
Use `JSON.stringify(body)` when setting the request body.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
12
Resources
nanographql — npm install nanographql · libregistry