facebook / facebook/relay

Fragment null after parent query is refetched and object is changed

Open
#4,222 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

I'm running into an issue where a fragment that is loaded using `fetchQuery` is null, which I believe is due to its containing query being refetched, and then this fragment is omitted in the later fetch.

Our flow looks something like this:
User opens our app and fetches a query like
```
latestPost {
id
...PostFragment
}
```

after running this query, we call `environment.retain(createOperationDescriptor(getRequest(query), variables));` to ensure that it is retained in the store.
When the result is obtained, we will manually hold onto the `latestPost` object (say A) in our own local array.

However later, the user might pull-to-refresh, we will refetch this query, and a new object (say B) will be retrieved and then added onto our array. In this case though, when we call `useFragment` on the previously fetched object (A), it returns `undefined`. This makes some sense as the response for the query has been replaced with the new object.

In this case, is it possible to somehow retain these objects regardless? If not, what should we do to ensure that the results of these queries are kept around? A hacky solution might be to add a fake timestamp variable to all these requests so that they are kept in the store regardless.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.