Registry / devops / graphql-import-node

graphql-import-node

JSON →
library0.0.5jsnpmunverified

Enables Node.js to import `.graphql` files as compiled GraphQL DocumentNode objects using require.extensions. Current stable version is 0.0.5 (last release). Low maintenance, no recent updates. Differs from alternatives (e.g., webpack graphql-tag/loader) by being a simple Node.js hook without bundler dependency. Requires peer dependency `graphql` and must be loaded before any GraphQL file imports. Supports CommonJS, ESM (via import), TypeScript (with typings), and Jest.

npm install graphql-import-node
INSTALL
IMPORT
SIG · GRAPHQL-IMPORT-NOD
G
graphql-import-node
devopsjavascriptv0.0.5
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.

register hook
import 'graphql-import-node'
import graphql-import-node
Default import not provided; use side-effect import.
TypeScript type declaration
import 'graphql-import-node'
No explicit type export; importing the module side-effect adds typings for .graphql files.
Jest transform
"^.+\.graphql$": "graphql-import-node/jest"
Configure in Jest's transform map, not an import.

Shows how to register the hook and import a .graphql file as a DocumentNode

// Install: npm install graphql-import-node graphql // In your entry file (e.g., index.js): require('graphql-import-node/register'); // or with ES modules: import 'graphql-import-node'; // Then import .graphql files: const typeDefs = require('./schema.graphql'); // import * as typeDefs from './schema.graphql'; // TypeScript console.log(typeDefs); // DocumentNode object
Debug
Known issues
breakingUse of require.extensions can interfere with other tools (e.g., Jest custom transforms) if not properly configured.
fix
Ensure the hook is loaded before any GraphQL imports; in Jest use the provided jest transform instead.
affects: all
gotchaThe package must be imported as a side-effect; there is no default or named export. Attempting to import a symbol will fail.
fix
Use `import 'graphql-import-node'` without curly braces or assigning to a variable.
affects: all
deprecatedPackage has not been updated in several years; may not work with newer Node.js versions (e.g., ESM-only projects).
fix
Consider alternatives like graphql-tag/loader or custom ESM loader for .graphql files.
affects: all
Errors
Common errors & fixes
Cannot find module 'graphql-import-node/register'
Missing or incorrect installation (e.g., devDependencies vs dependencies).
fix
Run `npm install graphql-import-node` and ensure it's in your package.json dependencies.
TypeError: (0 , _graphql.parse) is not a function
Missing or incompatible peer dependency `graphql`.
fix
Run `npm install graphql` to install the peer dependency.
Unexpected token '.' in JSON at position 0
Using `import schema from './schema.graphql'` (default import) instead of `import * as schema`.
fix
Use `import * as schema from './schema.graphql'` (namespace import) because the module exports a DocumentNode object, not a default export.
Upgrade
Version history
0.0.5latest on npm
Audit
Dependencies
graphqlrequiredpeer dependency – generates DocumentNode objects that are part of the GraphQL package
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
graphql-import-node — npm install graphql-import-node · libregistry