Registry / devops / graphql-import-loader

graphql-import-loader

JSON →
library0.2.1jsnpmunverified

Webpack loader for graphql-import that resolves GraphQL import statements (e.g., `# import { Type } from './type.graphql'`) in `.graphql` files. Current version 0.2.1, last updated in 2018. This package is unmaintained; the repository is archived. It was part of the deprecated Graphcool ecosystem. Alternatives: use `graphql-import` directly with `raw-loader` or `@graphql-tools/load` and `@graphql-tools/graphql-file-loader`. The loader returns the imported schema as a string.

npm install graphql-import-loader
INSTALL
IMPORT
SIG · GRAPHQL-IMPORT-LOA
G
graphql-import-loader
devopsjavascriptv0.2.1
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.

graphql-import-loader (webpack rule)
import typeDefs from './schema.graphql'
const typeDefs = require('./schema.graphql')
Since the loader returns a string, the import can be used as a default import or require. However, if using ES modules, use the import statement as shown. Using require may cause issues with webpack's ES module detection.
webpack use config
use: [{ loader: 'graphql-import-loader' }]
use: 'graphql-import-loader'
Omitting the array brackets is valid but uncommon. The loader works with a single string or object configuration.
TypeScript type
declare module '*.graphql' { const content: string; export default content; }
No type declaration
To use the imported string inside TypeScript, you must provide a declaration file for .graphql modules. Without it, TypeScript will error.

Configures webpack to resolve GraphQL import statements and use the resulting string in JavaScript.

// Install // npm install --save-dev graphql-import-loader // webpack.config.js module.exports = { module: { rules: [ { test: /\.graphql$/, exclude: /node_modules/, use: [{ loader: 'graphql-import-loader' }] } ] } }; // schema.graphql # import { User } from './user.graphql' type Query { users: [User!]! } // user.graphql type User { id: ID! name: String! } // app.js import typeDefs from './schema.graphql'; console.log(typeDefs); // prints the resolved schema string
Debug
Known issues
deprecatedThis package is deprecated and the repository is archived. It relies on graphql-import, which is also deprecated.
fix
Use @graphql-tools/load and @graphql-tools/graphql-file-loader or use raw-loader with graphql-import directly.
affects: >=0.0.0
gotchaThe loader only resolves imports relative to the importing file; it does not resolve from node_modules or aliases unless configured.
fix
Ensure all import paths are relative or use webpack resolve.alias.
affects: >=0.0.0
gotchaTypeScript users need a module declaration for *.graphql files; otherwise TypeScript will not recognize the import.
fix
Add a declaration file: declare module '*.graphql' { const content: string; export default content; }
affects: >=0.0.0
Errors
Common errors & fixes
Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type.
Webpack is not configured to use graphql-import-loader for .graphql files.
fix
Add the loader rule as shown in the quickstart. Ensure the test matches .graphql and the exclude is correct.
Error: Cannot find module 'graphql-import'
graphql-import is a peer dependency not explicitly listed; it must be installed.
fix
npm install --save-dev graphql-import
Cannot find module './some.graphql'
The import path in the .graphql file is incorrect or the file doesn't exist.
fix
Check the relative path and ensure the source file exists. The import paths are relative to the current file.
Upgrade
Version history
0.2.1latest on npm
Audit
Dependencies
graphql-importrequiredProvides the core import resolution logic; this loader is a thin wrapper.
Agent activity
6 hits · last 30 days
node
6
Resources
graphql-import-loader — npm install graphql-import-loader · libregistry