-
-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug when updating deeply nested lists with
@parentID
(#682)
* Provide parentType to addMany subscriptions The parentType in addFieldSubscription was hardcoded to 'asdf'. This causes issues when using multiple nested @list directives, as using the [ListName]_(insert|remove|toggle) operations with @parentID attempted to look for a parent with type 'asdf'. Signed-off-by: Jonas Jacobsen <[email protected]> * e2e testing of nested lists Route for testing nested lists has been added to e2e/sveltekit, Modles have been added to the e2e/_api GQL schema, and a simple "database" with sample data has been added to the resolvers. Signed-off-by: Jonas Jacobsen <[email protected]> * Changeset Signed-off-by: Jonas Jacobsen <[email protected]> * Move e2e operation files to appropriate route Operation files only used by src/routes/stores/nested-list are now placed appropriately. Signed-off-by: Jonas Jacobsen <[email protected]> * Simple test for nested lists Adds a simple test for testing data with nested lists. The test adds the cities/books/libraries database to the cache, and adds first a city, then a library. Next, a subscription is added, before adding a book to the cache, and it is verified that the book is added to the library. Signed-off-by: Jonas Jacobsen <[email protected]> * test verifies fix * fix imports * clarify changeset * clean up tests more Signed-off-by: Jonas Jacobsen <[email protected]> Co-authored-by: Alec Aivazis <[email protected]>
- Loading branch information
1 parent
878eb37
commit 57577ee
Showing
15 changed files
with
420 additions
and
5 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 | ||
--- | ||
|
||
Fix bug when updating deeply nested lists with @parentID |
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,98 @@ | ||
<script lang="ts"> | ||
import { browser } from '$app/environment'; | ||
import { | ||
GQL_Cities, | ||
GQL_AddCity, | ||
GQL_AddLibrary, | ||
GQL_AddBook, | ||
GQL_DeleteCity, | ||
GQL_DeleteLibrary, | ||
GQL_DeleteBook | ||
} from '$houdini'; | ||
$: browser && GQL_Cities.fetch(); | ||
const addCity = (event: Event) => { | ||
const target = event?.target as HTMLInputElement; | ||
GQL_AddCity.mutate({ name: target.value }); | ||
target.value = ''; | ||
}; | ||
const deleteCity = (event: Event) => { | ||
const target = event?.target as HTMLButtonElement; | ||
if (!target.dataset.id) { | ||
return; | ||
} | ||
GQL_DeleteCity.mutate({ city: target.dataset.id }); | ||
}; | ||
const addLibrary = (event: Event) => { | ||
const target = event?.target as HTMLInputElement; | ||
if (!target.dataset.id) { | ||
return; | ||
} | ||
GQL_AddLibrary.mutate({ city: target.dataset.id, name: target.value }); | ||
target.value = ''; | ||
}; | ||
const deleteLibrary = (event: Event) => { | ||
const target = event?.target as HTMLButtonElement; | ||
if (!target.dataset.id) { | ||
return; | ||
} | ||
GQL_DeleteLibrary.mutate({ library: target.dataset.id }); | ||
}; | ||
const addBook = (event: Event) => { | ||
const target = event?.target as HTMLInputElement; | ||
if (!target.dataset.id) { | ||
return; | ||
} | ||
GQL_AddBook.mutate({ library: target.dataset.id, title: target.value }); | ||
target.value = ''; | ||
}; | ||
const deleteBook = (event: Event) => { | ||
const target = event?.target as HTMLButtonElement; | ||
if (!target.dataset.id) { | ||
return; | ||
} | ||
GQL_DeleteBook.mutate({ book: target.dataset.id }); | ||
}; | ||
</script> | ||
|
||
<h1>Nested - List</h1> | ||
|
||
<ul> | ||
{#each $GQL_Cities.data?.cities ?? [] as city} | ||
<li> | ||
{city?.id}: {city?.name} | ||
<button data-id={city?.id} on:click={deleteCity}>Delete</button> | ||
<ul> | ||
{#each city?.libraries ?? [] as library} | ||
<li> | ||
{library?.id}: {library?.name} | ||
<button data-id={library?.id} on:click={deleteLibrary}>Delete</button> | ||
<ul> | ||
{#each library?.books ?? [] as book} | ||
<li> | ||
{book?.id}: {book?.title} | ||
<button data-id={book?.id} on:click={deleteBook}>Delete</button> | ||
</li> | ||
{/each} | ||
<li><input data-id={library?.id} on:change={addBook} /></li> | ||
</ul> | ||
</li> | ||
{/each} | ||
<li><input data-id={city?.id} on:change={addLibrary} /></li> | ||
</ul> | ||
</li> | ||
{/each} | ||
<li> | ||
<input on:change={addCity} /> | ||
</li> | ||
</ul> | ||
|
||
<pre>{JSON.stringify($GQL_Cities?.data, null, 4)}</pre> |
6 changes: 6 additions & 0 deletions
6
e2e/sveltekit/src/routes/stores/nested-list/MUTATION.AddBook.gql
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 @@ | ||
mutation AddBook($library: ID!, $title: String!) { | ||
addBook(library: $library, title: $title) { | ||
id | ||
...Book_List_insert @append(parentID: $library) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
e2e/sveltekit/src/routes/stores/nested-list/MUTATION.AddCity.gql
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 @@ | ||
mutation AddCity($name: String!) { | ||
addCity(name: $name) { | ||
id | ||
...City_List_insert | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
e2e/sveltekit/src/routes/stores/nested-list/MUTATION.AddLibrary.gql
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 @@ | ||
mutation AddLibrary($city: ID!, $name: String!) { | ||
addLibrary(city: $city, name: $name) { | ||
id | ||
...Library_List_insert @append(parentID: $city) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
e2e/sveltekit/src/routes/stores/nested-list/MUTATION.DeleteBook.gql
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 @@ | ||
mutation DeleteBook($book: ID!) { | ||
deleteBook(book: $book) { | ||
id @Book_delete | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
e2e/sveltekit/src/routes/stores/nested-list/MUTATION.DeleteCity.gql
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 @@ | ||
mutation DeleteCity($city: ID!) { | ||
deleteCity(city: $city) { | ||
id @City_delete | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
e2e/sveltekit/src/routes/stores/nested-list/MUTATION.DeleteLibrary.gql
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 @@ | ||
mutation DeleteLibrary($library: ID!) { | ||
deleteLibrary(library: $library) { | ||
id @Library_delete | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
e2e/sveltekit/src/routes/stores/nested-list/QUERY.Cities.gql
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 Cities { | ||
cities @list(name: "City_List") { | ||
id | ||
name | ||
libraries @list(name: "Library_List") { | ||
id | ||
name | ||
books @list(name: "Book_List") { | ||
id | ||
title | ||
} | ||
} | ||
} | ||
} |
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.
57577ee
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-phi-fawn.vercel.app
docs-houdinigraphql.vercel.app
docs-git-main-houdinigraphql.vercel.app
houdinigraphql.com
www.houdinigraphql.com
57577ee
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