5

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.

Deepak Kumar Padhy
  • 4,128
  • 6
  • 43
  • 79

1 Answers1

3

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/

vkashyap
  • 41
  • 4