-
-
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.
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]>
- Loading branch information
Showing
11 changed files
with
292 additions
and
1 deletion.
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
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
6 changes: 6 additions & 0 deletions
6
e2e/sveltekit/src/lib/graphql/operations/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/lib/graphql/operations/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/lib/graphql/operations/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/lib/graphql/operations/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/lib/graphql/operations/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/lib/graphql/operations/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 | ||
} | ||
} |
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
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> |