hey im getting a strange issue when using `@catch(...
# apollo-kotlin
a
hey im getting a strange issue when using
@catch(to: RESULT)
on a field that includes a fragment. Im finding that the json streamer is picking up the wrong type on rewind, and trying to parse wrong object (the field's that failed) as the parent type after failure occurs. example in 🧵
given:
Copy code
fragment SomeParentFragment on SomeCoreListingCollection {
    ...CoreListingCollectionTopLevelFragment
    collection @catch(to: RESULT) {
        ...SomeOtherListingCollectionTemplateInnerFragment
    }
}
when there is a failure in response,
Copy code
"node"{
"__typename": "SomeCoreListingCollection",
              "id": "someId",
              "blockId": 123456,
              "collection": {
                "__typename": "SomeOtherListingCollection" <--- trying to parse this inner object uding the `SomeCoreListingCollection`'s Adapter
              },
}


"extensions": {
    "valueCompletion": [
      {
        "message": "Cannot return null for non-nullable field SomeOtherListingCollection",
        "path": [
          "someExperience",
          "dynamicPaginatedBlocks",
          "edges",
          4,
          "node",
          "collection"
        ]
      }
    ]
generated code
Copy code
override fun fromJson(reader: JsonReader, customScalarAdapters: CustomScalarAdapters): com.***.fragment.SomeCoreListingCollectionTemplateFragment {
      var __typename: String? = null
      var _collection: FieldResult<com.***.fragment.SomeCoreListingCollectionTemplateFragment.Collection?>? = null

      while (true) {
        when (reader.selectName(RESPONSE_NAMES)) {
          0 -> __typename = StringAdapter.fromJson(reader, customScalarAdapters)
          1 -> _collection = Collection.obj(true).nullable().errorAware().catchToResult().fromJson(reader, customScalarAdapters)
          else -> break
        }
      }

      reader.rewind() <— rewind fails?
      val _coreListingCollectionTopLevelFragment = com.***.fragment.CoreListingCollectionTopLevelFragmentImpl_ResponseAdapter.CoreListingCollectionTopLevelFragment.fromJson(reader, customScalarAdapters)

      return com.***.fragment.CoreProductRecsListingCollectionTemplateFragment(
        __typename = __typename ?: missingField(reader, "__typename"),
        collection = _collection ?: missingField(reader, "collection"),
        coreListingCollectionTopLevelFragment = _coreListingCollectionTopLevelFragment
      )
    }
when it rewinds it uses the top level fragment's (
SomeCoreListingCollectionTemplateFragment
) adapter on the collection child itself. for its peeked data is the
Copy code
"__typename": "SomeOtherListingCollection"
inside
colleciton
field. not the top level
m
Could it be that
collection
is a merged field that has different
@catch
directives?
a
Collection is a union type, but no other catch directives
m
And is
collection
queried through another path in your query?
I added an attempt at a minimal reproducer there. Sadly it doesn't reproduce.
If you can share your schema + query + json I can look into it tomorrow (you can share privately to martin@apollographql.com if you prefer). If not, would be great to have a minimal reproducer.
This uses exception handling to handle errors. This sounds like a
endObject()
being skipped because an exception was thrown
a
Yeah, let me see if I can send to you tomorrow. It’s a slightly complex schema so I will try to trim down the fields like I did above.
m
I'll dig more tomorrow, I think I'm onto something. I'll let you know if I need more details
a
On my phone , but I’ll paste my original error I saw later. It was something about expecting end object and got array , or inverse
I went through a few workarounds to push the error lower with no luck (the last of which I sent over)
m
Yea, the JsonReader is stateful and throwing in the middle of an object doesn't close that object
👍 1
We could
try {} finally {}
but even that is not enough because we need to actually consume (==skip) remaining entries
Looks like we either need to buffer everything or not use exception handling for
@catch
a
I’m happy to test!
❤️ 1
m
PR is merged. If everything goes well, SNAPSHOTs should appear in ~30min
a
Awesome thanks. I’ll check in the AM ❤️
Will have to also upgrade to 5.x probably to test?. It shouldn’t be bad anyways, been meaning to do that
m
We'll backport if needed
👍 1
a
what snapshot version should I be using?
@mbonnin i am unable to browse the maven snapshots ui to find it due to it being unavailable
Copy code
Due to a bug with the underlying service we rely on to provide SNAPSHOT hosting, we've had to temporarily remove browse access for SNAPSHOT releases. You should still be able to publish and consume SNAPSHOT releases as usual, but you cannot browse them via the UI.
m
Yea Sonatype broke that 😞
You have the version in a badge on the repo, just make sure to use the "new" url
5.0.0-alpha.3-SNAPSHOT
maven("<https://central.sonatype.com/repository/maven-snapshots/>")
a
ah nice. thanks. yes i noticed that too, i was looking at v4 docs and was like..wait i should use v5 and found the url
ive tried to migrate, however im running into several workarounds and issues. is it possible to backport to a snapshot on 4.3.3x? this would provide the most easy path to testing the fix
m
Yes, definitely
a
thank you, ill keep reporting 5.x bugs as i find them
m
Thank you, this is super helpful 🙏
K 1
a
for 4.x releases, is it available in the snapshots repo?
m
Mmm, I haven't checked that in a while but this CI job has passed so I'm assuming yes
a
thank you! willl test either today or monday
m
Thanks!
a
ok so i have another issue happening now. maybe I can DM you with more info?
sent more info in DM. i think its due to multiple nested fields, catches, and fragments. hope it helps!