在graphQL服务器中使用SQL数据源实现嵌套游标分页的最佳方法是什么?
如何使用中继esk模式(使用SQL数据源)中的嵌套游标管理有效的数据获取在graphQL服务器中使用SQL数据源实现嵌套游标分页的最佳方法是什么?,sql,graphql,graphql-js,relay,Sql,Graphql,Graphql Js,Relay,如何使用中继esk模式(使用SQL数据源)中的嵌套游标管理有效的数据获取 您是否尝试使用一个复杂的SQL查询来解决N+1问题,即“先限制args\u”、“按args\u排序”和“WHERE cursor>:args\u after” 您是否对数据库运行2个查询并使用facebook数据加载器 例如,我有一个架构,结构如下: enum BookSortKeys { ID, TITLE, PRICE, UPDATED_AT, CREATED_AT } enum
enum BookSortKeys {
ID,
TITLE,
PRICE,
UPDATED_AT,
CREATED_AT
}
enum ReviewSortKeys {
ID,
REVIEW,
UPDATED_AT,
CREATED_AT
}
type Book {
id: ID!
title: String!
description: String
price: Float!
updatedAt: String!
createdAt: String!
reviews("""
Returns the elements that come after the specified cursor.
"""
after: String
"""
Returns the elements that come before the specified cursor.
"""
before: String
"""
Returns up to the first `n` elements from the list.
"""
first: Int
"""
Returns up to the last `n` elements from the list.
"""
last: Int
"""
Reverse the order of the underlying list.
"""
reverse: Boolean = false
"""
Sort the underlying list by the given key.
"""
sortKey: ReviewSortKeys = ID): ReviewConnection!
}
type Query {
books("""
Returns the elements that come after the specified cursor.
"""
after: String
"""
Returns the elements that come before the specified cursor.
"""
before: String
"""
Returns up to the first `n` elements from the list.
"""
first: Int
"""
Returns up to the last `n` elements from the list.
"""
last: Int
"""
Supported filter parameters:
- `title`
- `id`
- `price`
- `description`
- `created_at`
- `updated_at`
"""
query: String
"""
Reverse the order of the underlying list.
"""
reverse: Boolean = false
"""
Sort the underlying list by the given key.
"""
sortKey: BookSortKeys = ID): BookConnection!
}
type ReviewConnection {
pageInfo: PageInfo!
edges: [ReviewEdge!]!
}
type ReviewEdge {
cursor: String!
node: Review!
}
type BookConnection {
pageInfo: PageInfo!
edges: [BookEdge!]!
}
type BookEdge {
cursor: String!
node: Book!
}
type PageInfo {
hasNextPage: Boolean!
hasPreviousPage: Boolean!
}
type Review {
review: String!
id: ID!
updatedAt: String!
createdAt: String!
}
type Mutation {
}
schema {
query: Query
mutation: Mutation
}
我希望执行如下查询,并以最有效的方式检索数据
query GET_BOOKS {
books(first:10, sortKey: PRICE, reverse: true) {
pageInfo {
hasNextPage
hasPreviousPage
}
edges {
cursor
node {
id
title
description
reviews(after:"base64-cursor" first: 5, sortKey: CREATED_AT) {
edges {
node{
review
}
}
}
}
}
}
}
我可以很容易地将top查询(book)的所有分页参数转换为sql语句,但是使用嵌套游标,我只能看到2个选项(如上所述)。。。在实施这些选项之前,我面临的当前问题是:
限制
和WHERE createdAt>:after\u cursor\u val
SELECT*FROM reviews“reviews”WHERE“reviews”。bookId IN(…批处理的图书ID列表)
-添加限制
、按
排序和WHERE createdAt>:游标
是否会提供意外的结果,因为我的结果集是跨多个“图书ID”的条目的混合同时,我决定将数据加载器方法作为基线实现,从那里评估性能并优化特定用例。我认为这与强大的安全措施相结合是最好的方法。对于那些感兴趣的人。让我知道你的想法!