Apollo-client: [Batching] Query merging seems to discard variables only used in directives

Created on 23 Aug 2016  路  5Comments  路  Source: apollographql/apollo-client

Similarly to #562, when we activate batching with shouldBatch, variables only used in directives are not injected correctly in the merged query.

For instance, let's say I'm performing the following query:

query SomeQuery($assertion: Boolean!) {
  fieldTrue @include(if: $assertion)
  fieldFalse @skip(if: $assertion)
}

it will be rendered in the batch query the following way:

query ___composed($___SomeQuery___requestIndex_1___assertion: Boolean!) {
  ___SomeQuery___requestIndex_0___fieldIndex_0: fieldTrue @include(if: $assertion)
  ___SomeQuery___requestIndex_0___fieldIndex_1: fieldFalse @skip(if: $assertion)
}

Resulting in the following error:

Variable "$assertion" is not defined by operation "___composed".
馃悶 bug

Most helpful comment

Yeah, this can be fixed pretty easily by looking into directives within renameVariables inside queries/queryMerging.ts. The number of edge cases on this query merging thing is pretty staggering.

All 5 comments

I'll try to take a look at it, if I find something, let's do a PR!

But believe me, once I'm able to activate batching in my codebase, trust me, that means the feature is really stable, I have all of the twisted scenarios you can expect! 馃槅

Yeah, this can be fixed pretty easily by looking into directives within renameVariables inside queries/queryMerging.ts. The number of edge cases on this query merging thing is pretty staggering.

@Poincare pretty busy right now but will do when I have time, thanks for the pointers!

@Poincare patch in #584

Was this page helpful?
0 / 5 - 0 ratings