-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve support for unions and interfaces (#747)
* 🚸 UPDATE: tentative repro #731 * 🚸 NEW: e2e tests for union-result * use inline snapshots for artifact tests * subscription selection includes fields and type-dependent fields indepdently * update tests * fix type errors * update snapshots * fix unsubscribe tests * fix few bugs * all tests pass * failing test for abstract fields * can read and write abstract fields * reading, writing, and subscribing to abstract selections * simplify selection walk when subscribing * update snapshots * flattenSelection flattens inline fragments * embed typeMap in abstract selection * comment * fix list operations * dry up selection lookup for a type * tweak * avoid infinite recursion * changeset * remove unused imports * ignore masking for generating selections * only ignore masking for queries * test for interface to interface inline fragment * update snapshot Co-authored-by: jycouet <[email protected]>
- Loading branch information
1 parent
758683f
commit 7a34399
Showing
40 changed files
with
18,063 additions
and
12,456 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': patch | ||
'houdini-svelte': patch | ||
--- | ||
|
||
Fix issue when working with unions and interfaces |
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
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,8 @@ | ||
<script lang="ts"> | ||
import UserNodesResult from './UserNodesResult.svelte'; | ||
import UserResult from './UserResult.svelte'; | ||
</script> | ||
|
||
<UserNodesResult /> | ||
|
||
<UserResult id="1" /> |
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,14 @@ | ||
query UserNodesResult($forceMessage: Boolean!) { | ||
userNodesResult(snapshot: "union-result", forceMessage: $forceMessage) { | ||
... on UserNodes { | ||
totalCount | ||
nodes { | ||
id | ||
name | ||
} | ||
} | ||
... on Message1 { | ||
message | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
e2e/sveltekit/src/routes/union-result/UserNodesResult.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,16 @@ | ||
<script lang="ts"> | ||
import { CachePolicy, GQL_UserNodesResult } from '$houdini'; | ||
async function getAllUsers() { | ||
await GQL_UserNodesResult.fetch({ | ||
variables: { forceMessage: false }, | ||
policy: CachePolicy.CacheAndNetwork | ||
}); | ||
} | ||
</script> | ||
|
||
<button id="getAllUsers" on:click={getAllUsers}>GET AllUsers</button> | ||
|
||
<div id="result"> | ||
<pre>{JSON.stringify($GQL_UserNodesResult?.data, null, 2)}</pre> | ||
</div> |
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,11 @@ | ||
query UserResult($id: ID!, $forceMessage: Boolean!) { | ||
userResult(snapshot: "union-result", forceMessage: $forceMessage, id: $id) { | ||
... on User { | ||
id | ||
name | ||
} | ||
... on Message1 { | ||
message | ||
} | ||
} | ||
} |
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,16 @@ | ||
<script lang="ts"> | ||
import { CachePolicy, GQL_UserResult } from '$houdini'; | ||
export let id: string; | ||
async function getUser() { | ||
await GQL_UserResult.fetch({ | ||
variables: { id, forceMessage: false }, | ||
policy: CachePolicy.NetworkOnly | ||
}); | ||
} | ||
</script> | ||
|
||
<button id="getUser" on:click={getUser}>GET User</button> | ||
|
||
<pre>{JSON.stringify($GQL_UserResult?.data, null, 2)}</pre> |
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,70 @@ | ||
import { expect, test } from '@playwright/test'; | ||
import { routes } from '../../lib/utils/routes.js'; | ||
import { expectToBe, expect_1_gql, goto } from '../../lib/utils/testsHelper.js'; | ||
|
||
test.describe('union-result', () => { | ||
test('Get two stores and not resetting', async ({ page }) => { | ||
await goto(page, routes.union_result); | ||
|
||
// When we arrive on the page, we expect to see null in the result div | ||
await expectToBe(page, 'null'); | ||
|
||
// we click on the button to getAllUsers | ||
await expect_1_gql(page, 'button[id="getAllUsers"]'); | ||
|
||
const data = { | ||
userNodesResult: { | ||
totalCount: 8, | ||
nodes: [ | ||
{ | ||
id: 'union-result:1', | ||
name: 'Bruce Willis' | ||
}, | ||
{ | ||
id: 'union-result:2', | ||
name: 'Samuel Jackson' | ||
}, | ||
{ | ||
id: 'union-result:3', | ||
name: 'Morgan Freeman' | ||
}, | ||
{ | ||
id: 'union-result:4', | ||
name: 'Tom Hanks' | ||
}, | ||
{ | ||
id: 'union-result:5', | ||
name: 'Will Smith' | ||
}, | ||
{ | ||
id: 'union-result:6', | ||
name: 'Harrison Ford' | ||
}, | ||
{ | ||
id: 'union-result:7', | ||
name: 'Eddie Murphy' | ||
}, | ||
{ | ||
id: 'union-result:8', | ||
name: 'Clint Eastwood' | ||
} | ||
], | ||
__typename: 'UserNodes' | ||
} | ||
}; | ||
|
||
// expect data (of AllUsers) to be displayed | ||
await expectToBe(page, JSON.stringify(data, null, 2)); | ||
|
||
// we click on the button to getAllUsers | ||
const res = await expect_1_gql(page, 'button[id="getUser"]'); | ||
|
||
// expect data (of User) to be returned | ||
expect(res).toBe( | ||
`{"data":{"userResult":{"__typename":"User","id":"union-result:1","name":"Bruce Willis"}}}` | ||
); | ||
|
||
// expect data (of AllUsers) to still be here and displayed | ||
await expectToBe(page, JSON.stringify(data, null, 2)); | ||
}); | ||
}); |
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.
7a34399
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
docs – ./site
docs-houdinigraphql.vercel.app
www.houdinigraphql.com
docs-git-main-houdinigraphql.vercel.app
docs-phi-fawn.vercel.app
houdinigraphql.com
7a34399
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
docs-next – ./site
docs-next-houdinigraphql.vercel.app
docs-next-git-main-houdinigraphql.vercel.app
docs-next-kohl.vercel.app