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 4 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
32 changes: 21 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could use a comment - im not fully certain why we'd want to delete these properties. linking to the issue should be sufficient

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add a comment, the parser's loc fields include references to the query string and as your AST is deeper it becomes more overhead to ship/store the query

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 All @@ -156,5 +164,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