Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between field and connection in Graphql ruby?

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.

like image 546
Deepak Kumar Padhy Avatar asked Oct 18 '22 10:10

Deepak Kumar Padhy


1 Answers

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/

like image 161
vkashyap Avatar answered Oct 21 '22 09:10

vkashyap