Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 1760

Rescript Relay connecting mutation with refechable pagination

$
0
0

I do:

module AddMutation = %relay(`
  mutation AlbumRelayAddMutation(
    $input: CreateAlbum!,
    $connections: [ID!]!
  ) {
    createAlbum(input: $input)
    @prependEdge(connections: $connections)  {
      node {
        ...AlbumRelayFragment_album
      }
    }
  }
`)

And as I mentioned it prepends as long as there is no filter. After mutation, I do have another edge. At the moment I use useEffect to run refetch:

  let {data: albums_pag, refetch} = Fragment.usePagination(viewerRef.viewer.fragmentRefs)
  let album_nodes = albums_pag.albums->Fragment.getConnectionNodes

  Js.log3("runnig before effect", filter, album_nodes->Array.length)
  React.useEffect2(() => {
    Js.log3("runnig effect", filter, album_nodes->Array.length)
    let filter_: option<AlbumRelaysPaginationQuery_graphql.Types.filterAlbum> = switch filter {
    | Some(s) => Some({state: s})
    | None => None
    }
    let variables = Fragment.makeRefetchVariables(~filter=filter_)
    refetch(~variables)->RescriptRelay.Disposable.ignore
    None
  }, (filter, album_nodes->Array.length))

So if I have the filter set to None and run mutation I can see the effect running. But if I set the filter before the mutation runs it will result in the same amount of nodes for filtered data. Switching the filter back to None and I can see the extra edge. It seems like with the filter set I get some not updated set of edges.


Viewing all articles
Browse latest Browse all 1760

Trending Articles