Registry / testing / bun-graphql-loader

bun-graphql-loader

JSON →
library1.0.3jsnpmunverified

A Bun plugin for loading GraphQL (.gql, .graphql) files, using graphql-tag for parsing. It allows importing GraphQL documents directly in Bun projects, supporting named queries and fragments. Version 1.0.3 is stable and actively maintained. Unlike Vite plugins, this is tailored for Bun's plugin system. It requires Bun (>=0.6.0) and graphql-tag as a peer dependency. Ship with TypeScript declarations.

npm install bun-graphql-loader
INSTALL
IMPORT
SIG · BUN-GRAPHQL-LOADER
B
bun-graphql-loader
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.

bunGraphqlLoader
import bunGraphqlLoader from 'bun-graphql-loader'
const bunGraphqlLoader = require('bun-graphql-loader')
Default export, ESM only. CommonJS require will fail.
plugin
import { plugin } from 'bun'
import plugin from 'bun-plugin'
plugin is a named export from the 'bun' runtime package, not from this plugin.
ExampleQuery
import ExampleQuery from './example.gql'
import { ExampleQuery } from './example.gql'
If the file has a single query, use default import. Named imports are for multiple queries.

Shows how to install, configure, and use the loader in Bun.build and bun test, with TypeScript imports.

// Loader plugin for Bun import bunGraphqlLoader from 'bun-graphql-loader'; await Bun.build({ entrypoints: ['./src/index.ts'], outdir: './dist', plugins: [bunGraphqlLoader()], }); // For bun test, preload the plugin // create bunGraphqlLoader.ts: import { plugin } from 'bun'; import bunGraphqlLoader from 'bun-graphql-loader'; plugin(bunGraphqlLoader()); // In bunfig.toml: // [test] // preload = ['./bunGraphqlLoader.ts'] // Then import GraphQL files import query, { queries, fragments } from './schema.graphql'; console.log(query); // DocumentNode
Debug
Known issues
breakingrequire() not supported; ESM-only plugin
fix
Use import syntax instead of require().
affects: >=1.0.0
gotchaMultiple queries/fragments must be imported via named exports (_queries, _fragments) or use the default export for single query
fix
Use import Document, { _queries, _fragments } from './file.gql' to access all documents.
affects: >=1.0.0
gotchaTypeScript requires a module declaration for .gql/.graphql files
fix
Add 'declare module "*.gql"; declare module "*.graphql";' or a more specific type declaration.
affects: >=1.0.0
deprecatedgraphql-tag peer dependency must be installed separately
fix
Install graphql-tag with 'bun add graphql-tag' or 'npm install graphql-tag'.
affects: >=1.0.0
gotchaPlugin must be registered before building; lazy loading not supported
fix
Call bunGraphqlLoader() inside the plugins array at build time.
affects: >=1.0.0
gotchaUsing plugin with bun test requires preload configuration in bunfig.toml
fix
Create a preload file that calls plugin(bunGraphqlLoader()) and reference it in [test].preload.
affects: >=1.0.0
Errors
Common errors & fixes
Module not found: Can't resolve 'bun-graphql-loader'
Package not installed
fix
Run 'bun add --dev bun-graphql-loader'
require is not defined in ES module scope
Using require() instead of import
fix
Use 'import bunGraphqlLoader from "bun-graphql-loader"'
Cannot find module 'graphql-tag'
Missing peer dependency graphql-tag
fix
Run 'bun add graphql-tag'
No such plugin loader for file extension .gql
Plugin not registered before build
fix
Add bunGraphqlLoader() to the plugins array in Bun.build or use plugin() for test
TypeScript error: Cannot find module './schema.gql' or its corresponding type declarations.
Missing type declaration for .gql files
fix
Create a .d.ts file with 'declare module "*.gql";'
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
25 hits · last 30 days
node
22
Amazon
1
OpenAI (training)
1
Resources
bun-graphql-loader — npm install bun-graphql-loader · libregistry