While playing with Rescript Relay I encountered a problem with connections. That might be mostly Relay related problem but because I’m new to relay I’m not sure if I do something wrong with Rescript or if I’m lacking something on the Relay side.
Context:
I was trying to go through Rescript Relay tutorial and build a simple app.
I have a model that simplified SDL would look like this:
type Viewer {
id: RelayNodeID!
name: String!
albums(
after: String
before: String
first: Int
last: Int
filter: FilterAlbum
): AlbumConnection!
}
I use Rescript Relay Router to load queries and pass fragment refs to the page’s component where I use usePagination with refetch when I update filter value.
I went through Rescript Relay tutorial and added mutation and connections so my fragment looks like that:
module Fragment = %relay(`
fragment AlbumRelayContent_albums on Viewer
@refetchable(queryName: "AlbumRelayPaginationQuery")
@argumentDefinitions(
cursor: { type: "String" },
count: { type: "Int", defaultValue: 100 }
filter: { type: "FilterAlbum" }
)
{
...AlbumRelayComposerFragment
albums(first: $count, after: $cursor, filter: $filter)
@connection(key: "AlbumRelayAlbumsSection_albums")
{
edges {
node {
id
state
...AlbumRelayFragment_album
}
}
totalCount
pageInfo {
hasNextPage
startCursor
}
}
}
`)
And here is my problem:
Everything works fine till I add a filter to usePagination’s refetch. With the connection a new album mutation updates the store and I can see a new album in UI as long as the filter is not set. With a filter, it displays filtered albums without a new one (even if it matches the filter).
What should I do to update the store for filtered values? At this point, I’m unsure if I should update the fragment, code, or maybe even cursor on BE?