Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
],
"peerDependencies": {
"graphql": ">=0.9.0",
"rollup": "^2.78.0||^3.0.0||^4.0.0"
"rollup": "^2.78.0||^3.0.0||^4.0.0||^5.0.0"
},
"peerDependenciesMeta": {
"rollup": {
Expand All @@ -70,7 +70,7 @@
"devDependencies": {
"@rollup/plugin-buble": "^1.0.0",
"graphql": "^16.6.0",
"rollup": "^4.0.0-24"
"rollup": "catalog:rollup-next"
},
"types": "./types/index.d.ts"
}
11 changes: 7 additions & 4 deletions packages/graphql/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ export default function graphql({ include, exclude } = {}) {
const filter = createFilter(include, exclude);
// only .graphql, .graphqls (schema), and .gql files
const filterExt = /\.(graphqls?|gql)$/i;
// Rollup 5 appends encoded import attributes to the id as a query
const filterExtWithQuery = /\.(graphqls?|gql)(?:$|\?)/i;

return {
name: 'graphql',
transform: {
filter: {
id: filterExt
id: filterExtWithQuery
},
handler(source, id) {
if (!filter(id)) return null;
if (!filterExt.test(id)) return null;
handler(source, id, transformOptions) {
const rawId = (transformOptions && transformOptions.rawId) || id;
if (!filter(rawId)) return null;
if (!filterExt.test(rawId)) return null;

// XXX: this.cachable() in graphql-tag/loader
const code = toESModules(
Expand Down
2 changes: 2 additions & 0 deletions packages/graphql/test/fixtures/basic/index-with-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// eslint-disable-next-line import/prefer-default-export
export { default as doc } from './basic.graphql' with { type: 'graphql' };
12 changes: 12 additions & 0 deletions packages/graphql/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,15 @@ test('should support fragment imports with brackets and parentheses in file path
expect('doc' in module.exports).toBeTruthy();
expect(module.exports.doc.kind).toBe('Document');
});

test('should parse graphql files imported with import attributes', async () => {
const bundle = await rollup({
input: 'fixtures/basic/index-with-type.js',
plugins: [graphql({ include: '**/*.graphql', exclude: /attributes/ })]
});

const { module } = await testBundle(null, bundle);

expect('doc' in module.exports).toBeTruthy();
expect(module.exports.doc.kind).toBe('Document');
});
Loading
Loading