Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在graphQL服务器中使用SQL数据源实现嵌套游标分页的最佳方法是什么?_Sql_Graphql_Graphql Js_Relay - Fatal编程技术网

在graphQL服务器中使用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

如何使用中继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 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个选项(如上所述)。。。在实施这些选项之前,我面临的当前问题是:

  • 如果我采用纯SQL方法,是否有一种干净的方法来运行单个查询并在嵌套(联接)级别应用
    限制
    WHERE createdAt>:after\u cursor\u val
  • 如果可以实现上述功能,那么它是否比大规模的数据加载器性能更好?由于查询似乎是非常详细和复杂的,如果实现的话
  • 如果嵌套分页树增长(即具有4个嵌套分页的请求),会发生什么情况?在这里,一个纯查询对象级sql命令就足够了吗?或者在每个关系上添加解析器更具可扩展性(例如,book->reviews有一个sql查询来拉取这本书的所有特定评论,reviews->publications有一个查询来拉取它所在的所有评论的特定发布,依此类推,并在data loader中批处理它们)
  • 如果您使用数据加载器路径,批处理似乎使用了一个“WHERE IN”子句(即
    SELECT*FROM reviews“reviews”WHERE“reviews”。bookId IN(…批处理的图书ID列表)
    -添加
    限制
    排序和
    WHERE createdAt>:游标
    是否会提供意外的结果,因为我的结果集是跨多个“图书ID”的条目的混合
  • 从长远来看,我个人的感觉是,从代码的角度来看,纯sql方法将是混乱的,对此有何想法

  • 同时,我决定将数据加载器方法作为基线实现,从那里评估性能并优化特定用例。我认为这与强大的安全措施相结合是最好的方法。对于那些感兴趣的人。让我知道你的想法!