Skip to content

Commit

Permalink
Replace Object.assign in loader
Browse files Browse the repository at this point in the history
  • Loading branch information
wacii committed Apr 18, 2018
1 parent 549626a commit efe7078
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ module.exports = function(source) {
function oneQuery(doc, operationName) {
// Copy the DocumentNode, but clear out the definitions
var newDoc = Object.assign({}, doc);
var op = findOperation(doc, operationName);
newDoc.definitions = [op];
var newDoc = {
kind: doc.kind,
definitions: [findOperation(doc, operationName)],
loc: doc.loc
};
// Now, for the operation we're running, find any fragments referenced by
// it or the fragments it references
Expand Down Expand Up @@ -153,12 +154,6 @@ module.exports = function(source) {
module.exports = doc;
`

// Make copy before named exports are added to the doc
// see https://github.com/apollographql/graphql-tag/issues/168
outputCode += `
var docCopy = Object.assign({}, doc);
`

for (const op of doc.definitions) {
if (op.kind === "OperationDefinition") {
if (!op.name) {
Expand All @@ -171,7 +166,7 @@ module.exports = function(source) {

const opName = op.name.value;
outputCode += `
module.exports["${opName}"] = oneQuery(docCopy, "${opName}");
module.exports["${opName}"] = oneQuery(doc, "${opName}");
`
}
}
Expand Down

0 comments on commit efe7078

Please sign in to comment.