forked from HoudiniGraphql/houdini
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Offset pagination with variables (HoudiniGraphql#553)
* fix bug when counting offset page sizes with query variables * change snapshot used by intergation test * changeset * fixed issue refreshing current list
- Loading branch information
1 parent
e096943
commit 7666734
Showing
6 changed files
with
71 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'houdini': patch | ||
--- | ||
|
||
fixed bug when loading offset-based pages driven by query variable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
integration/src/routes/pagination/query/offset-variable/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<script lang="ts"> | ||
import { graphql, type OffsetVariablePaginationQueryStore, CachePolicy } from '$houdini'; | ||
const result: OffsetVariablePaginationQueryStore = graphql` | ||
query OffsetVariablePaginationQuery($limit: Int!) { | ||
usersList(limit: $limit, snapshot: "pagination-query-offset-variables") @paginate { | ||
name | ||
} | ||
} | ||
`; | ||
</script> | ||
|
||
<div id="result"> | ||
{$result.data?.usersList.map((user) => user?.name).join(', ')} | ||
</div> | ||
|
||
<button id="next" on:click={() => result.loadNextPage()}>next</button> | ||
|
||
<button id="refetch" on:click={() => result.fetch({ policy: CachePolicy.NetworkOnly })} | ||
>refetch</button | ||
> |
5 changes: 5 additions & 0 deletions
5
integration/src/routes/pagination/query/offset-variable/+page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function OffsetVariablePaginationQueryVariables() { | ||
return { | ||
limit: 2 | ||
}; | ||
} |
30 changes: 30 additions & 0 deletions
30
integration/src/routes/pagination/query/offset-variable/spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { routes } from '../../../../lib/utils/routes.js'; | ||
import { expect_1_gql, expectToBe, goto } from '../../../../lib/utils/testsHelper.js'; | ||
|
||
test.describe('offset paginatedQuery', () => { | ||
test('loadNextPage', async ({ page }) => { | ||
await goto(page, routes.Pagination_query_offset_variable); | ||
|
||
await expectToBe(page, 'Bruce Willis, Samuel Jackson'); | ||
|
||
// wait for the api response | ||
await expect_1_gql(page, 'button[id=next]'); | ||
|
||
// make sure we got the new content | ||
await expectToBe(page, 'Bruce Willis, Samuel Jackson, Morgan Freeman, Tom Hanks'); | ||
}); | ||
|
||
test('refetch', async ({ page }) => { | ||
await goto(page, routes.Pagination_query_offset_variable); | ||
|
||
// wait for the api response | ||
await expect_1_gql(page, 'button[id=next]'); | ||
|
||
// wait for the api response | ||
const response = await expect_1_gql(page, 'button[id=refetch]'); | ||
expect(response).toBe( | ||
'{"data":{"usersList":[{"name":"Bruce Willis","id":"pagination-query-offset-variables:1"},{"name":"Samuel Jackson","id":"pagination-query-offset-variables:2"},{"name":"Morgan Freeman","id":"pagination-query-offset-variables:3"},{"name":"Tom Hanks","id":"pagination-query-offset-variables:4"}]}}' | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters