Registry / devops / graphql-lodash

graphql-lodash

JSON →
library1.3.4jsnpmunverified

A library that integrates lodash-style data manipulation directly into GraphQL queries using the @_ directive, allowing query-time transformations like filtering, sorting, and mapping. Current stable version is 1.3.4, with irregular releases. It is experimental and designed for client-side usage; server-side use is discouraged. Key differentiator: collocates data fetching and transformation in one query, reducing post-processing code.

npm install graphql-lodash
INSTALL
IMPORT
SIG · GRAPHQL-LODASH
G
graphql-lodash
devopsjavascriptv1.3.4
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.

graphqlLodash
import { graphqlLodash } from 'graphql-lodash'
import graphqlLodash from 'graphql-lodash'
Named export only; no default export.
graphqlLodash (CommonJS)
const { graphqlLodash } = require('graphql-lodash')
const graphqlLodash = require('graphql-lodash')
CommonJS require must destructure named export.
GQLLodash (browser UMD global)
window.GQLLodash.graphqlLodash(query)
GQLLodash.graphqlLodash(query)
In browser without module bundler, the library exports a global GQLLodash object.
Types (TypeScript)
import { graphqlLodash } from 'graphql-lodash'
TypeScript types are shipped with the package; types are automatically resolved.

Demonstrates basic graphql-lodash usage: creating a query with @_ directives, stripping directives via graphqlLodash, then applying transform to the response data.

import { graphqlLodash } from 'graphql-lodash'; const queryWithTransform = ` query { allPeople @_(get: "people") { people @_(filter: "height > 150") { name height } } } `; const { query, transform } = graphqlLodash(queryWithTransform); fetch('https://swapi.apis.guru', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ query }), }) .then(res => res.json()) .then(data => { const transformedData = transform(data); console.log(transformedData); });
Debug
Known issues
deprecatedgraphql-lodash is experimental and not recommended for production use. No recent releases or maintenance activity.
fix
Evaluate alternatives or contribute to the project; use at your own risk.
affects: >=1.0.0
gotchaThe @_ directive uses lodash method names but not all lodash functions are available. The exact set depends on the version installed.
fix
Check the node_modules/graphql-lodash source or docs for supported methods; default set includes core methods like get, filter, map, reduce, sortBy, groupBy, etc.
affects: >=1.0.0
breakingBREAKING CHANGE: Version 1.0.0 changed the export from default to named export (graphqlLodash).
fix
Use import { graphqlLodash } from 'graphql-lodash' instead of import graphqlLodash from 'graphql-lodash'.
affects: >=1.0.0
gotchaThe transform function expects data as the first argument, not the entire response object. Passing response directly will cause errors.
fix
Call transform(result.data) or transform(result) if result is the data object.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: graphqlLodash is not a function
Using default import instead of named import (import graphqlLodash from 'graphql-lodash')
fix
Use import { graphqlLodash } from 'graphql-lodash'
Cannot read property 'data' of undefined
Calling transform on the fetch response object directly instead of response.data
fix
Ensure you pass the data property: transform(result.data)
Syntax Error: Expected Name, found "@"
GraphQL server does not support custom directives; the query must be preprocessed with graphqlLodash to strip the @_ directive before sending to server.
fix
Use graphqlLodash to get the cleaned query string and send that to the server.
Upgrade
Version history
1.3.4latest on npm
Audit
Dependencies
lodashrequiredProvides the lodash functions (e.g., get, maxBy) used in query transformations.
graphqloptionalParses GraphQL AST; used if query is passed as string.
Agent activity
6 hits · last 30 days
node
6
Resources
graphql-lodash — npm install graphql-lodash · libregistry