-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for required arguments on paginated fragments (#1253)
- Loading branch information
1 parent
c08c598
commit 21ef04b
Showing
22 changed files
with
658 additions
and
109 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,6 @@ | ||
--- | ||
'houdini-svelte': patch | ||
'houdini': patch | ||
--- | ||
|
||
Add support for required arguments in paginated fragments |
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
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
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
42 changes: 42 additions & 0 deletions
42
e2e/kit/src/routes/pagination/fragment/required-arguments/+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,42 @@ | ||
<script lang="ts"> | ||
import { graphql, paginatedFragment } from '$houdini'; | ||
$: queryResult = graphql(` | ||
query UserFragmentRequiredArgsQuery( | ||
$snapshot: String! = "pagination-fragment-required-arguments" | ||
) @load { | ||
user(id: "1", snapshot: $snapshot) { | ||
id | ||
name | ||
...TestFragment @with(snapshot: $snapshot) | ||
} | ||
} | ||
`); | ||
$: fragmentResult = paginatedFragment( | ||
$queryResult.data?.user ?? null, | ||
graphql(` | ||
fragment TestFragment on User @arguments(snapshot: { type: "String!" }) { | ||
usersConnectionSnapshot(first: 2, snapshot: $snapshot) @paginate { | ||
edges { | ||
node { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
} | ||
`) | ||
); | ||
</script> | ||
|
||
<div id="result"> | ||
{$fragmentResult.data?.usersConnectionSnapshot.edges.map(({ node }) => node?.name).join(', ')} | ||
</div> | ||
|
||
<div id="pageInfo"> | ||
{JSON.stringify($fragmentResult.pageInfo)} | ||
</div> | ||
|
||
<button id="next" on:click={() => fragmentResult.loadNextPage()}>next</button> |
48 changes: 48 additions & 0 deletions
48
e2e/kit/src/routes/pagination/fragment/required-arguments/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,48 @@ | ||
import { test } from '@playwright/test'; | ||
import { routes } from '../../../../lib/utils/routes.js'; | ||
import { | ||
expectToContain, | ||
expect_0_gql, | ||
expect_1_gql, | ||
expect_to_be, | ||
goto | ||
} from '../../../../lib/utils/testsHelper.js'; | ||
|
||
test.describe('forwards cursor paginatedFragment with required arguments', () => { | ||
test('loadNextPage', async ({ page }) => { | ||
await goto(page, routes.Pagination_fragment_required_arguments); | ||
await expect_to_be(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 expect_to_be(page, 'Bruce Willis, Samuel Jackson, Morgan Freeman, Tom Hanks'); | ||
}); | ||
|
||
test('page info tracks connection state', async ({ page }) => { | ||
await goto(page, routes.Pagination_fragment_required_arguments); | ||
|
||
const data = [ | ||
'Bruce Willis, Samuel Jackson, Morgan Freeman, Tom Hanks', | ||
'Bruce Willis, Samuel Jackson, Morgan Freeman, Tom Hanks, Will Smith, Harrison Ford', | ||
'Bruce Willis, Samuel Jackson, Morgan Freeman, Tom Hanks, Will Smith, Harrison Ford, Eddie Murphy, Clint Eastwood' | ||
]; | ||
|
||
// load the next 3 pages | ||
for (let i = 0; i < 3; i++) { | ||
// wait for the request to resolve | ||
await expect_1_gql(page, 'button[id=next]'); | ||
|
||
// check the page info | ||
await expect_to_be(page, data[i]); | ||
} | ||
|
||
// make sure we have all of the data loaded | ||
await expect_to_be(page, data[2]); | ||
|
||
await expectToContain(page, `"hasNextPage":false`); | ||
|
||
await expect_0_gql(page, 'button[id=next]'); | ||
}); | ||
}); |
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
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
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
Oops, something went wrong.