-
Notifications
You must be signed in to change notification settings - Fork 178
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
Changes from 2 commits
54f5432
ac061dd
72425c4
029c39e
5628384
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. | ||
|
@@ -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. | ||
|
@@ -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]') { | ||
|
@@ -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; | ||
|
@@ -126,7 +134,7 @@ function parseDocument(doc) { | |
parsed = processFragments(parsed); | ||
parsed = stripLoc(parsed, false); | ||
docCache[cacheKey] = parsed; | ||
|
||
return parsed; | ||
} | ||
|
||
|
@@ -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); | ||
|
@@ -156,5 +164,7 @@ function gql(/* arguments */) { | |
gql.default = gql; | ||
gql.resetCaches = resetCaches; | ||
gql.disableFragmentWarnings = disableFragmentWarnings; | ||
gql.print = require('graphql/language/printer'); | ||
gql.parser = parser | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't look like these two names are consistent - should it be "parse" rather than "parser"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @stubailo I did a search: and saw some typings expecting What do you suggest? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The module is called There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay i will export the parse function instead of the whole parser There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was exporting the whole lib |
||
|
||
module.exports = gql; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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