Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache webpack loader #16

Merged
merged 1 commit into from
Nov 2, 2016
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ This package only has one feature - it caches previous parse results in a simple

### Webpack preprocessing

This package also includes a [webpack loader](https://webpack.github.io/docs/loaders.html). There are many benefits over this approach, which saves GraphQL ASTs processing time on client-side, optimizes bundle size and enable queries to be separated from script over `.graphql` files.
This package also includes a [webpack loader](https://webpack.github.io/docs/loaders.html). There are many benefits over this approach, which saves GraphQL ASTs processing time on client-side and enable queries to be separated from script over `.graphql` files.

```js
loaders: [
Expand Down
5 changes: 4 additions & 1 deletion loader.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const gql = require('./');

module.exports = source => `module.exports = ${JSON.stringify(gql`${source}`)};`;
module.exports = function(source) {
this.cacheable();
return `module.exports = ${JSON.stringify(gql`${source}`)};`;
};
2 changes: 1 addition & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const assert = require('chai').assert;
});

it('parses queries through webpack loader', () => {
const source = loader('{ testQuery }');
const source = loader.call({ cacheable() {} }, '{ testQuery }');
const ast = JSON.parse(source.replace('module.exports = ', '').slice(0, -1));

assert.equal(ast.kind, 'Document');
Expand Down