Registry / devops / broccoli-graphql-filter

broccoli-graphql-filter

JSON →
library1.0.1jsnpmunverified

Broccoli filter plugin (v1.0.1) that converts .graphql files into ES6 modules exporting an AST representation of the query, supporting fragment imports via graphql-import syntax. Can parse at build time (JSON AST) or runtime (graphql-tag template literals). Requires Node >=10 and peer dependency graphql ^14|^15|^16. Differentiates from other GraphQL preprocessing tools by integrating directly with the Broccoli build pipeline, enabling efficient asset compilation in Ember apps or other Broccoli-based projects.

npm install broccoli-graphql-filter
INSTALL
IMPORT
SIG · BROCCOLI-GRAPHQL-F
B
broccoli-graphql-filter
devopsjavascriptv1.0.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.

default
import myQuery from './my-query.graphql'
const myQuery = require('./my-query.graphql')
Outputs ESM default export; CJS require returns the default exported doc object
default (with keepExtension)
import myQuery from './my-query.graphql'
When keepExtension is true, import using the .graphql extension directly
dynamic import
const mod = await import('./my-query.graphql'); mod.default
import('./my-query').then(mod => mod.default)
With keepExtension: true the file path must include the extension

Shows installation, Brocfile configuration, and importing the AST from a .graphql file.

// Install broccoli plugin and peer deps npm install --save-dev broccoli-graphql-filter graphql // In your Brocfile.js or broccoli plugin const filterGraphQL = require('broccoli-graphql-filter'); let tree = filterGraphQL(['app'], { keepExtension: false, parseAt: 'build-time' }); module.exports = tree; // Example .graphql file: my-query.graphql // # import * from './my-fragment.graphql' // query myQuery { foo { ...MyFragment } } // In application code: import myQuery from './my-query'; console.log(myQuery); // AST object
Debug
Known issues
breakingImport syntax changed to graphql-import subset in v1.0.0 - old import syntax (#import ... from ...) no longer works
fix
Update your .graphql files to use the new import syntax: # import * from 'path' or # import Foo from 'path'
affects: >=1.0.0
deprecatedparseAt: 'run-time' option requires graphql-tag to be installed as a runtime dependency
fix
Install graphql-tag: npm install graphql-tag
affects: >=1.0.0
gotchaWhen using keepExtension: true, the output file has .graphql.js extension; import must omit .js and include .graphql
fix
Import as './my-query.graphql' instead of './my-query'
affects: >=1.0.0
gotchaNode version requirement is 10.* or >=12 – Node 12+ recommended
fix
Use Node >=12
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'graphql'
Missing peer dependency graphql
fix
npm install graphql
Parse error: Unknown type "Foo"
Fragment import file not found or not properly linked
fix
Ensure import path matches actual file and use correct import syntax: # import * from './my-fragment'
Cannot find module 'graphql-tag'
When parseAt: 'run-time', graphql-tag is required but not installed
fix
npm install graphql-tag
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
graphqlrequiredpeer dependency required to parse GraphQL documents to AST at build time
graphql-tagoptionalrequired at runtime when parseAt is set to 'run-time' for template literals
Agent activity
8 hits · last 30 days
node
8
Resources
broccoli-graphql-filter — npm install broccoli-graphql-filter · libregistry