quick question, I don't have a minimal repro but t...
# apollo-kotlin
w
quick question, I don't have a minimal repro but there's a chance I encountered a bug in how
@include
directive is handled: when I have two fragments on the same type, and I
@include(if: false)
one of them, then the whole query doesn't return from the cache. Quick outline:
Copy code
query Foo(doInclude: Boolean!) {
  foo {
    bar {
      ...firstFragmentOnBar
      ...secondFragmentOnBar
      ...thirdFragmentOnBar@include(if: doInclude)
    }
  }
}

fragment firstFragmentOnBar on Bar {
  fieldforFirstFragment { ... }
}

fragment secondFragmentOnBar on Bar {
  fieldforSecondFragment { ... }
}

fragment thirdFragmentOnBar on Bar {
  fieldforThirdFragment { ... }
}
with the above when I observe
Foo(false)
from the cache, and another query refreshes it, then the first cache-only query doesn't emit proper data. I was pretty confused since I did see data in the normalized cache, there was no error or anything. I feel it's a bug because when I move the
@include
inside the fragment, it works as expected
Copy code
query Foo(doInclude: Boolean!) {
  foo {
    bar {
      ...firstFragmentOnBar
      ...secondFragmentOnBar
      ...thirdFragmentOnBar
    }
  }
}

fragment firstFragmentOnBar on Bar {
  fieldforFirstFragment { ... }
}

fragment secondFragmentOnBar on Bar {
  fieldforSecondFragment { ... }
}

fragment thirdFragmentOnBar on Bar {
  fieldforThirdFragment@include(if: doInclude) { ... }
}
Am I wrong assuming the first variant is correct and should work? Or perhaps there's a subtle difference that makes the two not equivalent? Please let me know if you need more details and I'll try making a self-contained repro πŸ™‚
b
hmm no I can't think of a good reason it shouldn't work, it looks like a bug
w
I definitely see a different behavior so I suppose something is happening πŸ™‚ I opened an issue here: https://github.com/apollographql/apollo-kotlin/issues/5338, it's definitely low priority because there exists a trivial workaround. For now I'm leaving it but if you need a more specific repro let me know πŸ™‚
b
thanks a lot for the issue! πŸ‘
it may be interesting to try with v4 as there was recently a bug fix related to cache/fragment/include
πŸ‘€ 1
w
Yep v4 seems to work πŸŽ‰
b
ah-ah! So probably the same issue. You may try with the beta.1 (which didn't have the fix) to confirm πŸ™‚
w
Btw is it correct migration? I want to keep using
ApolloCall
πŸ€”
And beta.1 fails πŸ™‚
b
And beta.1 fails
Ok thanks for confirming πŸ™
about
ApolloCall
why do you now need the apply?
oh I see
storePartialResponses
isn't generic, I guess we changed that
πŸ˜… No wait it is
w
image.png
but something's off πŸ‘€ It's
emitCacheMisses
that causes the failure
but it should now be removed so it's all good πŸ‘
It doesn't use
addExecutionContext
so it doesn't return
T
πŸ™‚
βœ… 1
s
Hmm what's this apolloFactory createApolloCall etc πŸ‘€? Are these your own apis over Apollo Kotlin?
b
> but it should now be removed so it's all good ooh yeah makes sense. Heads up if you haven't looked at v4 before. Migration guide is here. The main change is about error handling, where we've been avoiding throwing exceptions. You can opt-in to the old v3 behavior with a configuration flag. Also in the IDE plugin there's a migration tool, to automate a few things.
w
Ah yes, I didn't notice it's our wrapper, but it's a simple
apolloClient.query(operation)
. In any case I was confused with wrapper types and thought they changed in v4 but I was looking at old code πŸ˜„ It's just the
emitCacheMisses
inferred type in the end
gratitude thank you 1
Thanks for the heads up, I'm aware there are some changes in the error handling, but I didn't realize it's beta time already! I think it's a good time to try the migration and report any bugs πŸ™‚
b
yes please!! πŸ™ πŸ™‚
last heads up - we're still thinking of error handling in v4, so things may still evolve
πŸ‘ 1
πŸ‘€ 1