1

How do you update your connections/edges when adding or deleting edges in an app?

TL;DR: Should I

  1. know all fragments and connections in the app, and handle them whenever I do these mutations?
  2. break my app into multiple context (i.e. pages), and refetch my connections when changing context?

For a simple context (like add user to a list of users) I have the overview of my queries and fragments and @appendEdge and @deleteEdge works fine.

But in a larger context it gets a lot more complicated. In my case I have a page with a feed of stories which can be bookmarked. At another page (far far away) I have all my bookmarked stories.

For deleting bookmarks, I could use @deleteEdge and have a list of connections ids that listens on deleted bookmarks. That could be solved with some kind of observer pattern, which could look like:

  useEffect(() => observeBookmarkedStories(me.stories.__id), [me])

For adding bookmarks it gets more complicated. I could use the same approach, but that should then somehow tell what extra fragments should be loaded for a bookmark - and I don't think that is possible at runtime

As I see it, I have the two options stated above. If I go with option 1, all developers needs to know the entire relay part of the app when doing add/delete mutations. Options 2 gives some looser coupling (usually nice), but more network request and stale data for a brief moment.

There could easily be a third options that solves all my problems.

  • How are you navigating between your pages? As far as I know you only need to update connections which are in the same view you're currently in, since navigating to a new page will refetch your data anyway – Sebastian Cruz Apr 28 '22 at 13:13

0 Answers0