Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop Bundling GraphQL in the module #46

Merged
merged 5 commits into from
Feb 8, 2017
Merged
Show file tree
Hide file tree
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
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