-
Notifications
You must be signed in to change notification settings - Fork 113
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
cache readFragment return null #484
Comments
The problem is the use of fragment PostFragment on Post {
// ...
isFavorited: favoritedUsers(where: {id: $userId}){
totalCount
}
isLiked: likedUsers(where: {id: $userId}){
totalCount
}
// ...
} For this reason, |
I think you need to pass the variables used in the fragment (userId) also to the fragment request |
Yes, but I can just pass client.cache.readFragment(GPostFragmentReq(
(b) => b..idFields = {"id": posts[index]?.node?.id},
)) |
I see. This sound like a bug. I'll look into it.
extension MyReadFragment on Cache {
/// Reads denormalized data from the Cache for the given fragment.
TData? readFragment2<TData, TVars>(
FragmentRequest<TData, TVars> request, {
bool optimistic = true,
Map<String, dynamic> variables = {}
}) {
final json = denormalizeFragment(
read: optimistic ? optimisticReader : (dataId) => store.get(dataId),
document: request.document,
idFields: request.idFields,
fragmentName: request.fragmentName,
// this is custom
variables: variables,
typePolicies: typePolicies,
addTypename: addTypename,
dataIdFromObject: dataIdFromObject,
possibleTypes: possibleTypes,
);
return json == null ? null : request.parseData(json);
}
} ? |
Yes, it's working. 👍 |
how can use this extension in |
You'll probably have to access to cache directly through some other means (like setting it as global variable or something like this) and bypass the cache proxy as workaround until this is fixed properly in ferry |
OK, thanks for your help |
This should be fixed in I added a fragment similar to yours: https://github.com/gql-dart/gql/pull/382/files#diff-86124cb045d0e2d1f35d90d940bfe72821613a8ca4999a43bcc9615aab57c719 and verified that now the variable userId is properly included: https://github.com/gql-dart/gql/pull/382/files#diff-0053d21550d6ab52170d9f97f8b74fadf9fd1d7da1b5357d6742bc854ed70d05R30. Could you add this gql_code_builder: 0.7.1-alpha+1676138216360 via dependency_override and see if this works for you? |
Very good, yes, I will definitely check it, but it seems to be fixed |
I try to use
readFragment
to get thePostFragment
by id but it always returns nullShow example
Debug results:
readFragment:
null
cache identify:
store get:
cache keys:
Show ferry client
Show GraphQL Query
Show GraphQL Fragments
Dependencies
The text was updated successfully, but these errors were encountered: