-
Notifications
You must be signed in to change notification settings - Fork 177
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
Fragments bodies where added multiple times (duplicates) #278
base: master
Are you sure you want to change the base?
Conversation
@lanwin: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/ |
@lanwin wondering if you could follow up with @apollo-cla and get this PR on track. This would help me solve the issue I'm having as well with codegen and graphql-tag |
I already did this a while ago. As you can see, the pullrequest is mergeable. |
Is this getting merged any time soon? |
If you look closely at the commit history, there wasnt any commit since nearly one year ago. So it seems it will not happen in the near future. |
If you are suffering from this problem. Ive created a minimal version of graphql-tag which outputs only the source of the query and did not have this problem. https://gist.github.com/lanwin/bdc33d0bf291851bda48d17f98b98ff2 |
@lanwin, I wrote an extension which wraps |
|
I've attempted to apply this patch for Regardless, I'l leave my patches/graphql-tag+2.12.4.patchdiff --git a/node_modules/graphql-tag/lib/graphql-tag.umd.js b/node_modules/graphql-tag/lib/graphql-tag.umd.js
index 629f159..ce3d19b 100644
--- a/node_modules/graphql-tag/lib/graphql-tag.umd.js
+++ b/node_modules/graphql-tag/lib/graphql-tag.umd.js
@@ -87,7 +87,11 @@
var result = literals[0];
args.forEach(function (arg, i) {
if (arg && arg.kind === 'Document') {
- result += arg.loc.source.body;
+ var body = arg.loc.source.body;
+ // Dont add body's that were already added by other documents
+ if (result.indexOf(body) === -1) {
+ result += body;
+ }
}
else {
result += arg;
diff --git a/node_modules/graphql-tag/lib/index.js b/node_modules/graphql-tag/lib/index.js
index 81db598..8f78f09 100644
--- a/node_modules/graphql-tag/lib/index.js
+++ b/node_modules/graphql-tag/lib/index.js
@@ -83,7 +83,11 @@ export function gql(literals) {
var result = literals[0];
args.forEach(function (arg, i) {
if (arg && arg.kind === 'Document') {
- result += arg.loc.source.body;
+ var body = arg.loc.source.body;
+ // Dont add body's that were already added by other documents
+ if (result.indexOf(body) === -1) {
+ result += body;
+ }
}
else {
result += arg; |
In scenarios where a fragment is nested and used multiple times graphql-tag includes the fragments bodies (source) multiple times. While its obviously wrong, our graphql server also rejecting that requests.
Scenario
Current output (v2.10.1 and before)
Expected output (this Pullrequest)
I also added a test for this scenario.