Skip to content
Open
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
12 changes: 8 additions & 4 deletions loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ function expandImports(source, doc) {

module.exports = function(source) {
this.cacheable();
// can be simplified later to this.options?.esm
// options is optional here as that breaks where a fake webpack context is used
// that doesn't have options
const esm = (this.options || {}).esm;
const doc = gql`${source}`;
let headerCode = `
var doc = ${JSON.stringify(doc)};
Expand All @@ -63,7 +67,7 @@ module.exports = function(source) {

if (operationCount < 1) {
outputCode += `
module.exports = doc;
${esm ? "export default doc;" : "module.exports = doc;"}
`
} else {
outputCode += `
Expand Down Expand Up @@ -162,8 +166,8 @@ module.exports = function(source) {

return newDoc;
}
module.exports = doc;

${esm ? "export default doc;" : "module.exports = doc;"}
`

for (const op of doc.definitions) {
Expand All @@ -178,7 +182,7 @@ module.exports = function(source) {

const opName = op.name.value;
outputCode += `
module.exports["${opName}"] = oneQuery(doc, "${opName}");
${esm ? `export const ${opName}` : `module.exports[${JSON.stringify(opName)}]`} = oneQuery(doc, ${JSON.stringify(opName)});
`
}
}
Expand Down