Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support graphql with pages/cursors #19

Open
AndersDJohnson opened this issue Mar 26, 2020 · 0 comments
Open

feat: support graphql with pages/cursors #19

AndersDJohnson opened this issue Mar 26, 2020 · 0 comments
Assignees
Labels
enhancement New feature or request hacktoberfest help wanted Extra attention is needed

Comments

@AndersDJohnson
Copy link
Owner

AndersDJohnson commented Mar 26, 2020

We could consider some kind of support for GraphQL and deeply nested page values or cursors.

A shorthand inline query syntax with template literal interpolation using last call's response:

fetchPaginate('https://graphql.example.com', {
  graphql: (previous) => `
    query someQuery {
      products(page: ${previous?.data?.products?.nextPage || 1}) {
        id
        nextPage
      }
    }
  `
})

Or, using a static query but dynamically re-defining variables for each paged call:

const query = `
  query someQuery($page: Int = 1, $type: String) {
    products(page: $page, type: $type) {
      id
      nextPage
    }
  }
`;

fetchPaginate('https://graphql.example.com', {
  graphql: {
    query,
    variables: (previous) => ({
      type: 'blog',
      page: previous?.data?.products?.nextPage
    })
  }
})
@AndersDJohnson AndersDJohnson added the enhancement New feature or request label Mar 26, 2020
@AndersDJohnson AndersDJohnson self-assigned this Mar 26, 2020
@AndersDJohnson AndersDJohnson added the help wanted Extra attention is needed label Oct 5, 2020
@AndersDJohnson AndersDJohnson changed the title feat: support pages/cursors for graphql feat: support graphql with pages/cursors Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request hacktoberfest help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant