Relay: Enhancement: Append/Prepend/Remove for plain GraphQLLists

Created on 9 Oct 2015  路  11Comments  路  Source: facebook/relay

I know that in docs it says that RANGE_ADD add new edge to connection, so I assume its only for connections (with edges and node).

So want to basically ask if there is some other option how to add item to normal graphql list without refetching the whole list or if its planned.

Thanks.

enhancement new-core-api

Most helpful comment

The other issue with requiring connections is that you have to do a lot of boilerplate to model the types, edges and connections. Sometimes the items in an array may not even have a meaningful ID, so you have to somehow invent one. It's actually quite a lot of hoops to jump through just to be able to add an item to a simple array.

All 11 comments

@jardakotesovec Currently append/prepend/remove operations are only supported on connections and not for plain lists. In general connections are more powerful and we recommend using when designing schemas. I'll mark this as an enhancement - we'll accept contributions for similar operators for lists (e.g. append/prepend/remove).

Cross-referencing: I made a post on SO about the differences between connections and lists, with a link back here to this feature request.

The other issue with requiring connections is that you have to do a lot of boilerplate to model the types, edges and connections. Sometimes the items in an array may not even have a meaningful ID, so you have to somehow invent one. It's actually quite a lot of hoops to jump through just to be able to add an item to a simple array.

I use connections only where I expect long lists with pagination, but for other cases I also prefer to avoid boilerplate.

And since there is no reason not having these fine grained mutations also for lists, we just need someone amazing, who will implement it :-).

For posterity, the only way to deal with plural fields (i.e. a field of type GraphQLList) is to refetch the entire field which understandably sucks.

@wincent Maybe this issue also could be part of the #538? Just in case you have missed that.

Yeah, it's definitely related, @jardakotesovec, but I don't think we'll get to any list changes as part of that work, except indirectly (ie. we won't change lists to have connection-like features, but we might be able to make connections as easy as working with lists). Let's this keep this open until the dust settles from that work; we can close it if necessary once we know how things end up.

Is it possible to craft a getOptimisticResponse for GraphQLList based mutations? Brief experimentation with appending my new item onto the existing Relay array results in errors with client ids.

Thanks for filing this - this was great input as we developed the new core, which supports this feature (#1369).

Are there any news on this?

I'm sorry this issue has sat here for so long. In an attempt to clean up our issue queue we're closing some aging or unclear-action issues. Also, while this issue applies to Relay Classic, our team is trying to focus on Relay Modern going forward.

If this is something you'd like to see happen, then we'd be happy to review a pull request.

If this issue is still important to you, please feel free to reopen it with an update.

Was this page helpful?
0 / 5 - 0 ratings