AndersDJohnson / AndersDJohnson/fetch-paginate

feat: support graphql with pages/cursors

Offen
#19 0 Kommentare 0 Reaktionen 1 zugewiesene Person Beansprucht von @AndersDJohnson Auf GitHub ansehen
enhancement hacktoberfest help wanted
Vorherrschende Sprache
TypeScript
Sterne
27
Forks
3
Ø Merge
1 Min.
Gemergte PRs (30 T.)
2

Beschreibung

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:

```ts
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:

```ts
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
})
}
})
```

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.