Apollo iOS how to handle partial decoding failure

224 views Asked by At

I'm trying to see if there is a way to do more robust handling of partial decoding failures of Apollo generated Swift classes. Currently, if even one field of one object in an array fails to parse from the network response, the entire collection of objects fails to parse and our iOS client gets no data.

Our graphql is defined something like:

query mobile_getCollections() {
  getCollections() {
    // ... other fields

    items {
      activeRange {
        expires  // Int!
        starts   // Int!
      }
    }

  }
}

So the Apollo generated Swift code is expecting non-nil Ints when decoding these values. However, due to a backend error (that we would like to make the mobile clients more resilient to), the API will occasionally send us a malformed date String instead of a unix timestamp Int. This causes parsing of the entire mobile_getCollections result to fail, because the Apollo generated query class typing can't be perfectly satisfied.

Ideally, I'd like to just throw out the one item in the collection that failed to be parsed correctly and leave the remaining items intact. Is it possible to do something like that using Apollo?

(Yes, I know the real answer here is to fix the backend, but is there anything I can do in the mean time to more gracefully handle similar partial parsing failure issues?)

1

There are 1 answers

0
bhushan deshmukh On

https://www.apollographql.com/docs/ios/fetching/error-handling/ check this out ,might be helpful. i suggest you ignore the error if the data response is not nil.