Skip to contents

Creates the next_cursor function used by fabric_graphql_paginate() for the common hasNextPage and endCursor pagination fields

Usage

fabric_graphql_cursor(path, has_next = "hasNextPage", end_cursor = "endCursor")

Arguments

path

Character path from the result's data field to a connection object, for example "products" or c("viewer", "products"). This is the parent object that contains the pagination fields, not the items field

has_next

Name of the logical connection field indicating another page. Fabric commonly uses "hasNextPage"

end_cursor

Name of the connection field containing the opaque cursor Fabric commonly uses "endCursor"

Value

A function suitable for next_cursor in fabric_graphql_paginate(). For each page it returns the cursor when has_next is true, otherwise NULL

Examples

# Build a reusable extractor for a GraphQL connection named "products"
next_cursor <- fabric_graphql_cursor("products")

# This small local result shows the response shape expected by the extractor
page <- structure(
  list(data = list(products = list(
    hasNextPage = TRUE,
    endCursor = "opaque-cursor"
  ))),
  class = c("fabric_graphql_result", "list")
)

# TRUE plus a cursor tells the paginator to request another page
next_cursor(page)
#> [1] "opaque-cursor"