Registry / api / nest-graphql-endpoint

nest-graphql-endpoint

JSON →
library0.8.3jsnpmunverified

Version 0.8.3. A library for merging a remote GraphQL endpoint (e.g., GitHub's v4 API) into your local GraphQL schema. Wraps external queries under a field that resolves contextually, allowing per-user authenticated requests. Includes a pre-built helper for GitHub's API. Requires graphql ^16. Release cadence is low, with infrequent updates. Differentiator: nested GraphQL schema stitching without complex federation, designed for server-side use with Node v15+ (native AbortController).

npm install nest-graphql-endpoint
INSTALL
IMPORT
SIG · NEST-GRAPHQL-ENDPO
N
nest-graphql-endpoint
apijavascriptv0.8.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.

default
import nestGraphQLEndpoint from 'nest-graphql-endpoint'
const nestGraphQLEndpoint = require('nest-graphql-endpoint')
ESM-only package; does not export CommonJS. Use default import.
nestGitHubEndpoint
import nestGitHubEndpoint from 'nest-graphql-endpoint/lib/nestGitHubEndpoint'
Not exported from package root; must import from subpath. This is a common gotcha.
nestGraphQLEndpoint
import { nestGraphQLEndpoint } from 'nest-graphql-endpoint'
The package does not export a named export; only default export is available.

Merges a remote GraphQL endpoint into a parent schema under a new field with per-user auth context.

import { buildSchema, print } from 'graphql'; import nestGraphQLEndpoint from 'nest-graphql-endpoint'; const parentSchema = buildSchema(` type User { id: ID! name: String } `); const remoteSchemaIDL = ` type Query { viewer: User } type User { bio: String } `; const newSchema = nestGraphQLEndpoint({ parentSchema, parentType: 'User', fieldName: 'github', resolveEndpointContext: (source) => ({ accessToken: source.accessToken ?? '', }), executor: async (document, variables, context) => { const response = await fetch('https://api.github.com/graphql', { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${context.accessToken}`, }, body: JSON.stringify({ query: print(document), variables }), }); return response.json(); }, prefix: '_ext', batchKey: 'accessToken', schemaIDL: remoteSchemaIDL, }); console.log('Schema extended successfully');
Debug
Known issues
gotchaImporting nestGitHubEndpoint from the package root does not work; you must import from 'nest-graphql-endpoint/lib/nestGitHubEndpoint'
fix
Use import nestGitHubEndpoint from 'nest-graphql-endpoint/lib/nestGitHubEndpoint'
affects: >=0.1.0
gotchaPackage is ESM-only; using require() causes a SyntaxError
fix
Use import syntax or dynamic import in an ESM context.
affects: >=0.8.0
gotchaRequires Node v15.0.0 or later for native AbortController used internally
fix
Ensure Node version is 15.0.0 or higher, or use a polyfill.
affects: >=0.6.0
gotchaThe remote schema IDL must match the actual remote schema exactly; mismatches cause runtime errors
fix
Always fetch the latest schema IDL from the remote endpoint (e.g., via introspection) and ensure consistency.
affects: >=0.1.0
Errors
Common errors & fixes
SyntaxError: Cannot use import statement outside a module
Using require() instead of import in a CommonJS environment
fix
Switch to ESM by adding 'type": "module"' to package.json or use dynamic import.
TypeError: nestGraphQLEndpoint is not a function
Attempting to import nestGitHubEndpoint from package root instead of subpath
fix
Use import nestGitHubEndpoint from 'nest-graphql-endpoint/lib/nestGitHubEndpoint'
Error: batchKey is required when multiple queries share the same prefix
Missing batchKey in options when using prefix that may cause batching
fix
Add a batchKey (e.g., 'accessToken') to the options object.
Upgrade
Version history
0.8.3latest on npm
Audit
Dependencies
graphqlrequiredPeer dependency: required for schema manipulation and document printing.
Agent activity
29 hits · last 30 days
node
26
Resources
nest-graphql-endpoint — npm install nest-graphql-endpoint · libregistry