apollo-ios: SchemaConfiguration of Cache Keys not being called

Bug report

Hi,

I’m trying to migrate Apollo client from 0.53.0 to 1.0.3 into my app Xcode project under CocoaPods.

In my app code, I have some query watchers which work as expected: when a mutation payload updates something in the data of my local cache (which are parts of my query), relative watcher is fired perfectly.

After having upgraded Apollo client to 1.0.3, I notice my all query watchers are not triggered anymore in the cases they were with Apollo client 0.5.3.

Versions

Please fill in the versions you’re currently using:

  • apollo-ios SDK version: 1.0.3
  • Xcode version: 13.4.1
  • Swift version: 5.6.1
  • CocoaPods: 1.11.3

Steps to reproduce

When I try to add or remove a picture to a ride, relative query watcher is not fired when I receive my mutations payloads. Watcher policy doesn’t seem to be an investigation lead: both .returnCacheDataElseFetch and .returnCacheDataAndFetch are affected in my project.

My query (using fragments) and relative mutations

query GetRide($rideId: ID!) {
    ride(id: $rideId) {
        ...EndRideFragment
    }
}

fragment EndRideFragment on Ride {
    id
    name
    startTime
    isFavorite
    distance
    duration
    pictures {
        ...PictureFragment
    }
}

fragment PictureFragment on RidePicture {
    id
    url
    thumbnailUrl(height: 340)
}

mutation AddRidePicture($input: AddRidePictureInput!) {
    addRidePicture(input: $input) {
        ride {
            id
            pictures {
                id
            }
        }
        picture {
            ...PictureFragment
        }
    }
}

mutation DeleteRidePicture($id: ID!) {
    removeRidePicture(id: $id) {
        ride {
            id
            pictures {
                id
            }
        }
    }
}

My watchers (used with my previous query)

func watch<T: GraphQLQuery>(query: T) -> Observable<T.Data> {
    return self.client.rx.watch(query: query)
}

func watchAndFetch<T: GraphQLQuery>(query: T) -> Observable<T.Data> {
    return self.client.rx.watch(query: query, cachePolicy: .returnCacheDataAndFetch)
}

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 28 (20 by maintainers)

Most upvoted comments

Our plan is to get 1.0.6 out today, there’s a few fixes queued up already in there, and then 1.0.7 possibly before the end of the week. I’ll add this to the list of things to tackle for 1.0.7 - will that work?

Thanks for confirming it’s working @Narayane. The ApolloAPI vs Apollo difference is because you’re using CocoaPods which bundles everything together in one big module named the same as the pod.

@AnthonyMDev we could possibly do two column code samples for these? Or just a comment on that line in the samples.

The docs have been updated, and I’m fairly certain that fixing that configuration should solve your issue. If this is still a problem, feel free to re-open this issue.

The implementation of the cache key resolution (the one that you show in this comment) should be in that SchemaConfiguration.swift file. That function should be returning the correct CacheKeyInfo.

Implementing that function in your GraphQLAPI directly is not going to do anything. 😃

@Narayane Thanks for the info. Your setup looks correct. I’m going to do a little more investigation today, but I haven’t been able to reproduce this bug yet.

@AmadeusK525 Glad to hear that configuring cache keys correctly resolved this for you. Not sure why it’s not working for others!

Of course! Thanks for the transparency 🙂