Registry / api / graphql-binding

graphql-binding

JSON →
library2.5.2jsnpmunverified

GraphQL binding is a library for creating modular building blocks that embed existing GraphQL APIs into your own GraphQL server. It allows you to turn parts of GraphQL APIs into reusable components, supporting JavaScript, TypeScript, and Flow. Current stable version is 2.5.2, with irregular releases. Key differentiators: enables composition and reuse of GraphQL APIs, integrates with Prisma and other services. Note: the library is in maintenance mode; consider using modern alternatives like graphql-codegen or built-in federation.

npm install graphql-binding
INSTALL
IMPORT
SIG · GRAPHQL-BINDING
G
graphql-binding
apijavascriptv2.5.2
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.

Binding
import { Binding } from 'graphql-binding'
const Binding = require('graphql-binding')
ESM usage requires TypeScript or bundler; CommonJS works but the default export is different.
Binding as default
import Binding from 'graphql-binding'
const { Binding } = require('graphql-binding')
CommonJS default is an object; named import is recommended.
Binding class
const { Binding } = require('graphql-binding')
const Binding = require('graphql-binding').default
The CommonJS module exports an object with Binding as a property, not a default export.

Creates a binding from a GraphQL schema string and uses it to query a user.

import { Binding } from 'graphql-binding'; import { GraphQLClient } from 'graphql-request'; const client = new GraphQLClient('https://api.example.com/graphql', { headers: { Authorization: `Bearer ${process.env.API_KEY ?? ''}` }, }); const binding = new Binding({ schema: ` type Query { user(id: ID!): User } type User { id: ID! name: String! } `, fragmentReplacements: {}, before: () => console.log('Before query'), }); // Usage binding.query.user({ id: '1' }).then(user => console.log(user));
Debug
Known issues
deprecatedgraphql-binding is in maintenance mode and not actively developed. Consider using graphql-codegen or federation.
fix
Migrate to graphql-codegen (https://graphql-code-generator.com) or Apollo Federation.
affects: >=2.0.0
breakingBreaking: In version 2.0, the constructor API changed. The 'schema' parameter now expects a string or DocumentNode, not a GraphQLSchema object.
fix
Update constructor to pass schema as string or DocumentNode.
affects: >=2.0.0
breakingBreaking: The 'before' and 'after' hooks no longer receive the query document as second argument. Instead, they receive only the delegate function.
fix
Update hook signatures to (delegate: DelegateFunction) => void.
affects: >=2.0.0
gotchaCommonJS users: require('graphql-binding') returns an object, not the class directly. You must destructure { Binding }.
fix
Use const { Binding } = require('graphql-binding');
affects: >=2.0.0
gotchaIf you import using ES modules, ensure you have a bundler that handles TypeScript, as the package ships with TypeScript declarations but expects bundler for ESM.
fix
Use TypeScript and configure bundler to handle .ts files.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot find module 'graphql-binding'
Package not installed or incorrect import path.
fix
Run npm install graphql-binding or yarn add graphql-binding
TypeError: graphql_binding_1.Binding is not a constructor
Importing incorrectly: using default import when CommonJS is required.
fix
Use const { Binding } = require('graphql-binding'); or import { Binding } from 'graphql-binding';
Binding is not a constructor
Passing an object to require and trying to construct the object itself.
fix
Ensure you destructure Binding: const { Binding } = require('graphql-binding');
Upgrade
Version history
2.5.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
60 hits · last 30 days
node
54
OpenAI (training)
1
Resources
graphql-binding — npm install graphql-binding · libregistry