-
Notifications
You must be signed in to change notification settings - Fork 658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Defer: take @defer cases into account with normalized cache #3987
Conversation
✅ Deploy Preview for apollo-android-docs canceled.
|
...monMain/kotlin/com/apollographql/apollo3/cache/normalized/internal/ApolloCacheInterceptor.kt
Show resolved
Hide resolved
...monMain/kotlin/com/apollographql/apollo3/cache/normalized/internal/ApolloCacheInterceptor.kt
Show resolved
Hide resolved
apollo-api/src/commonMain/kotlin/com/apollographql/apollo3/api/AdapterContext.kt
Show resolved
Hide resolved
@@ -72,26 +74,25 @@ val CacheFirstInterceptor = object : ApolloInterceptor { | |||
} else { | |||
throw it | |||
} | |||
}.singleOrNull() | |||
}.map { response -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks the contract that CacheFirst
emits only once. I guess there's no real way around this but the doc needs to be updated
...monMain/kotlin/com/apollographql/apollo3/cache/normalized/internal/ApolloCacheInterceptor.kt
Outdated
Show resolved
Hide resolved
.../src/commonMain/kotlin/com/apollographql/apollo3/cache/normalized/FetchPolicyInterceptors.kt
Show resolved
Hide resolved
e2caa01
to
5ae4d7d
Compare
"""{"data":{"computers":[{"__typename":"Computer","id":"Computer1"}]},"hasNext":true}""", | ||
"""{"data":{"cpu":"386","year":1993,"screen":{"__typename":"Screen","resolution":"640x480"}},"path":["computers",0],"hasNext":true}""", | ||
"""{"data":{"isColor":false},"path":["computers",0,"screen"],"hasNext":false,"label":"a"}""", | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Dog) Food for thought: looks like we could use test builders to simplify those tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM !
2 potential follow ups:
- Use test builders in Tests
- Stop throwing in the flow instead expose
Response.exception
With defer, multiple elements can be emitted in Flows returned by the network, which prompted a few adaptations in the normalized cache interceptors.
Also, always read deferred fragments in the adapter when used to parse cached values.