I'm in the process of building a GraphQL API in a Rails 7 application, using the graphql-ruby gem.
In the app, users can create lists of catalogue items, and their lists can be manually ordered. So the simplified ActiveRecords look a bit like this:
class List < ApplicationRecord has_many :list_items has_many :items, through: :list_items end class ListItem < ApplicationRecord belongs_to :list belongs_to :item # attributes include :position, :updated_at, etc. end class Item < ApplicationRecord has_many :list_items has_many :lists, through: :list_items end What I'd like to be able to do is to include the ListItem's attributes within the edge of the response, e.g.:
list(id: $id) { title createdAt items { edges { position updatedAt node { id title thumbnailUrl } } } } I've tried creating custom Connection and Edge objects, but have so far failed to work out how to express that the edge has a direct ActiveRecord equivalence to a particular ListItem record such that I can retrieve the necessary attributes.
edgesis justlist_items? What isnode? You said lists can be ordered manually, but in your query there is not any order attribute, what do you mean?