Graphql ruby​​ 中的字段和连接之间的区别?

Dee*_*dhy 5 ruby ruby-on-rails graphql graphql-ruby

我是 Graphql 的新手。对于一个简单的用例,假设我有一个简单的模型,

  class Post < ActiveRecord::Base
   has_many :comments
  end
Run Code Online (Sandbox Code Playgroud)

下面是我的 graphql query_type.rb 中的代码

PostType = GraphQL::ObjectType.define do
 #field :comments, types[CommentType]
 #connection :comments, CommentType.connection_type
end
Run Code Online (Sandbox Code Playgroud)

两者都field and connection对我有用。但哪一种是正确的方法。

小智 3

连接将帮助您paginate在查询中使用 4 个默认参数(第一个、最后一个、之后和之前)连接到帖子的评论列表,而此处的字段将返回基本列表CommentType

有关连接分页的更多信息,请阅读此处

http://graphql.org/learn/pagination/