Skip to content

Commit

Permalink
Merge pull request #46 from apollographql/ParsePrint
Browse files Browse the repository at this point in the history
Stop Bundling GraphQL in the module
  • Loading branch information
abhiaiyer91 authored Feb 8, 2017
2 parents c5332e0 + 5628384 commit f7cf4c2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 3,535 deletions.
33 changes: 22 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,12 @@ function stripLoc (doc, removeLocAtThisLevel) {
delete doc.loc;
}

// https://github.com/apollographql/graphql-tag/issues/40
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 +149,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 All @@ -156,5 +165,7 @@ function gql(/* arguments */) {
gql.default = gql;
gql.resetCaches = resetCaches;
gql.disableFragmentWarnings = disableFragmentWarnings;
gql.print = require('graphql/language/printer');
gql.parse = parse;

module.exports = gql;
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
"babel-preset-es2015": "^6.9.0",
"babel-register": "^6.9.0",
"chai": "^3.5.0",
"graphql": "^0.9.0",
"graphql": "^0.9.1",
"mocha": "^2.5.3",
"webpack": "^1.13.1"
},
"peerDependencies": {
"graphql": "^0.9.x"
}
}
Loading

0 comments on commit f7cf4c2

Please sign in to comment.