Skip to content

Commit

Permalink
Pulling stripLoc changes from apollographql#46
Browse files Browse the repository at this point in the history
  • Loading branch information
jnwng committed Feb 24, 2017
1 parent 6c0739a commit 464cf29
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var parse = require('./parser').parse;
var parser = require('graphql/language/parser');

var parse = parser.parse;

// Strip insignificant whitespace
// Note that this could do a lot more, such as reorder fields etc.
Expand Down Expand Up @@ -38,8 +40,7 @@ function processFragments(ast) {
var sourceKey = cacheKeyFromLoc(fragmentDefinition.loc);

// We know something about this fragment
if (fragmentSourceMap.hasOwnProperty(fragmentName) &&
!fragmentSourceMap[fragmentName][sourceKey]) {
if (fragmentSourceMap.hasOwnProperty(fragmentName) && !fragmentSourceMap[fragmentName][sourceKey]) {

// this is a problem because the app developer is trying to register another fragment with
// the same name as one previously registered. So, we tell them about it.
Expand Down Expand Up @@ -73,11 +74,13 @@ function disableFragmentWarnings() {
printFragmentWarnings = false;
}

function stripLoc (doc, removeLocAtThisLevel) {
function stripLoc(doc, removeLocAtThisLevel) {
var docType = Object.prototype.toString.call(doc);

if (docType === '[object Array]') {
return doc.map(function(d) { return stripLoc(d, removeLocAtThisLevel); });
return doc.map(function (d) {
return stripLoc(d, removeLocAtThisLevel);
});
}

if (docType !== '[object Object]') {
Expand All @@ -90,6 +93,11 @@ function stripLoc (doc, removeLocAtThisLevel) {
delete doc.loc;
}

if (doc.loc) {
delete doc.loc.startToken;
delete doc.loc.endToken;
}

var keys = Object.keys(doc);
var key;
var value;
Expand Down Expand Up @@ -140,13 +148,13 @@ function gql(/* arguments */) {
var result = literals[0];

for (var i = 1; i < args.length; i++) {
if (args[i] && args[i].kind && args[i].kind === 'Document') {
result += args[i].loc.source.body;
} else {
result += args[i];
}
if (args[i] && args[i].kind && args[i].kind === 'Document') {
result += args[i].loc.source.body;
} else {
result += args[i];
}

result += literals[i];
result += literals[i];
}

return parseDocument(result);
Expand Down

0 comments on commit 464cf29

Please sign in to comment.