I am new to Graphql. For a simple use case, Let's say i have simple model,
class Post < ActiveRecord::Base
has_many :comments
end
Below is the code in my graphql query_type.rb
PostType = GraphQL::ObjectType.define do
#field :comments, types[CommentType]
#connection :comments, CommentType.connection_type
end
Both field and connection
works for me. But which one is the right way to go.
Connection will help you paginate
through the list of comments connected to the post with 4 default arguments (first, last, after and before) in the query, whereas field here would return a basic list of CommentType
For more on pagination with connection, read up here
http://graphql.org/learn/pagination/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With