graphql-persisted-document-loader
Advanced tools
Comparing version 1.0.1 to 2.0.0
19
index.js
@@ -6,3 +6,2 @@ const vm = require('vm'); | ||
const queryTransformers = require('persistgraphql/lib/src/queryTransformers'); | ||
const loadModuleRecursively = require('./load-module-recursively'); | ||
@@ -19,3 +18,3 @@ module.exports = function graphQLPersistedDocumentLoader(content) { | ||
deps.push(new Promise((resolve, reject) => { | ||
loadModuleRecursively(context, file, (err, source, sourceMap, module) => { | ||
context.loadModule(file, (err, source, sourceMap, module) => { | ||
if (err) { | ||
@@ -85,3 +84,17 @@ reject(err); | ||
if (queries.length > 1) { | ||
throw new Error('Only one operation per file is allowed'); | ||
queries | ||
.map(query => { | ||
const matched = query.match(/^(mutation|query)\ ([^\ \(\{]*)/) | ||
if (!matched) { | ||
return false | ||
} | ||
return { | ||
operationName: matched[2], | ||
id: generateIdForQuery(options, query) | ||
} | ||
}) | ||
.filter(isValid => !!isValid) | ||
.forEach(({ id, operationName }) => { | ||
content += `${os.EOL}module.exports["${operationName}"].documentId = ${JSON.stringify(id)};` | ||
}) | ||
} else if (queries.length === 1) { | ||
@@ -88,0 +101,0 @@ const queryId = generateIdForQuery(options, Object.keys(queryMap)[0]); |
{ | ||
"name": "graphql-persisted-document-loader", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "Webpack loader that adds a documentId to a compiled graphql document, which can be used when persisting/retrieving documents", | ||
@@ -13,3 +13,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"graphql-tag": "^2.5.0", | ||
"graphql-tag": "^2.9.2", | ||
"webpack": "^3.8.1", | ||
@@ -21,3 +21,6 @@ "webpack-dev-server": "^2.9.5" | ||
"persistgraphql": "^0.3.11" | ||
}, | ||
"peerDependencies": { | ||
"graphql-tag": "^2.8.0" | ||
} | ||
} |
@@ -15,3 +15,3 @@ # GraphQL Persisted Document Loader | ||
You need to have the [graphql-tag](https://github.com/apollographql/graphql-tag) package installed. | ||
You need to have the [graphql-tag](https://github.com/apollographql/graphql-tag) *(>= v2.8.0)* package installed. | ||
@@ -18,0 +18,0 @@ First install this package |
8557
3
4
96