Registry / testing / gql-dedup

gql-dedup

JSON →
library1.0.3jsnpmunverified

A drop-in replacement for graphql-tag that automatically deduplicates fragments when composing GraphQL queries. Version 1.0.3 is current and stable, with no significant release cadence. Unlike graphql-tag, which throws duplicate fragment errors, gql-dedup safely includes each fragment only once, enabling reusable fragment composition across deeply nested dependencies. Ships TypeScript types and requires graphql-tag ^2.0.0 and graphql ^14.0.0 as peer dependencies. Ideal for Apollo Client projects that share fragments across multiple queries.

npm install gql-dedup
INSTALL
IMPORT
SIG · GQL-DEDUP
G
gql-dedup
testingjavascriptv1.0.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.

gql
import gql from 'gql-dedup'
const gql = require('gql-dedup')
ESM-only package; CommonJS require will fail.
gql (named destructure)
import { gql } from 'gql-dedup'
import gql from 'gql-dedup'
Named export also available, but default export is the standard pattern.
resetCaches
import { resetCaches } from 'gql-dedup'
Utility to clear internal fragment cache; not commonly needed.

Demonstrates deduplication: both fragments are included, none duplicated.

import gql from 'gql-dedup'; const FRAG_A = gql` fragment FragA on User { name } `; const FRAG_B = gql` fragment FragB on User { email } `; const QUERY = gql` query { user { ...FragA ...FragB } } ${FRAG_A} ${FRAG_B} `; console.log(QUERY.loc.source.body);
Debug
Known issues
deprecatedgraphql-tag is unmaintained; gql-dedup is a recommended alternative.
fix
Replace import from 'graphql-tag' with 'gql-dedup'.
affects: *
gotchagql-dedup uses a global cache; repeated calls with same template literal may return cached result.
fix
Use resetCaches() to clear cache if needed.
affects: >=1.0.0
gotchaMust spread fragments via template literal interpolation, or they won't be included in output.
fix
Always use ${fragmentVar} after the GraphQL string.
affects: >=1.0.0
gotchaWorks only with graphql-tag ^2.0.0 and graphql ^14.0.0; incompatible with graphql 15+.
fix
Pin graphql to ^14.0.0 if using this library.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: gql_dedup_1.default is not a function
Using CommonJS require instead of ESM import.
fix
Change to 'import gql from "gql-dedup"' and ensure ESM module resolution.
GraphQLError: Fragment "FragDate" cannot be spread here as objects of type "User" can never be of type "String".
Fragment spread on incompatible type; not related to dedup.
fix
Ensure fragments are defined on correct types and used on compatible parent types.
Duplicate fragment name "FragDate" in document.
Using graphql-tag instead of gql-dedup, or forgetting to use gql-dedup import.
fix
Replace import from 'graphql-tag' with 'gql-dedup'.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
graphql-tagrequiredPeer dependency; gql-dedup wraps graphql-tag's parsing and adds deduplication logic.
graphqlrequiredPeer dependency; required for graphql-tag to function.
Agent activity
6 hits · last 30 days
node
6
Resources
gql-dedup — npm install gql-dedup · libregistry