Pagination 带限制的Graphql ruby分页生成n+1个查询
假设您有用户和订阅。您需要对用户的订阅进行分页。每个用户有不同数量的订阅。这是我想到的第一件事: users=User.whereid:[array].index\u by&:id查找用户并生成一个id为键的对象 subs=subs.whereuser\u id:[array].limit3.offset1为所有用户查找我们需要的subs subs.forEach{| s | users[s[:id]].subs在这里解决可能对某人有帮助。它应该是这样的带有分区的查询Pagination 带限制的Graphql ruby分页生成n+1个查询,pagination,graphql-ruby,Pagination,Graphql Ruby,假设您有用户和订阅。您需要对用户的订阅进行分页。每个用户有不同数量的订阅。这是我想到的第一件事: users=User.whereid:[array].index\u by&:id查找用户并生成一个id为键的对象 subs=subs.whereuser\u id:[array].limit3.offset1为所有用户查找我们需要的subs subs.forEach{| s | users[s[:id]].subs在这里解决可能对某人有帮助。它应该是这样的带有分区的查询 def query(q
def query(queryable, params) do
case params do
%{chapters: true, offset: offset, first: first} ->
last = offset + first
query = from r in queryable, select: r, select_merge: %{chapter_number: fragment("row_number() over (PARTITION by parent_id order by \"name\")")}
from r in subquery(query), select: %Wikisource.Book{id: r.id, name: r.name, info: r.info, preface: r.preface, info_html: r.info_html, preface_html: r.preface_html}, where: r.chapter_number >= ^offset and r.chapter_number < ^last
%{order_by: order_by, offset: from, first: size} -> from record in queryable, order_by: ^order_by, offset: ^from, limit: ^size