class GraphQL::Relay::RangeAdd

This provides some isolation from GraphQL::Relay internals.

Given a list of items and a new item, it will provide a connection and an edge.

The connection doesn’t receive outside arguments, so the list of items should be ordered and paginated before providing it here.

Examples

Example: Adding a comment to list of comments

post = Post.find(args[:post_id])
comments = post.comments
new_comment = comments.build(body: args[:body])
new_comment.save!

range_add = GraphQL::Relay::RangeAdd.new(
  parent: post,
  collection: comments,
  item: new_comment,
  context: context,
)

response = {
  post: post,
  comments_connection: range_add.connection,
  new_comment_edge: range_add.edge,
}