在Graphql Ruby中,字段(field)和连接(connection)有什么区别?

5

我是GraphQL的新手。针对一个简单的使用案例,假设我有一个简单的模型:

  class Post < ActiveRecord::Base
   has_many :comments
  end

以下是我在graphql query_type.rb中的代码:
PostType = GraphQL::ObjectType.define do
 #field :comments, types[CommentType]
 #connection :comments, CommentType.connection_type
end

在我看来,fieldconnection都可以使用。但哪个是正确的选择呢?

1个回答

3

Connection可以帮助你在查询中使用4个默认参数(first、last、after和before)浏览与帖子相关的评论列表,而field则会返回基本的CommentType列表。

想了解更多关于Connection分页的内容,请阅读这里:

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接