added basic graphql mapping

This commit is contained in:
Samuel Andert 2023-08-07 15:01:30 +02:00
parent 0c202e0ef6
commit 783548581c
3 changed files with 63 additions and 39 deletions

View File

@ -12,5 +12,10 @@
<p>{todo.text}</p> <p>{todo.text}</p>
{/each} {/each}
{/if} {/if}
<br />
dataTest:
{#if $me.x}
{JSON.stringify($me.x)}
{/if}
</section> </section>
</div> </div>

View File

@ -59,6 +59,15 @@
if (component.data?.map) { if (component.data?.map) {
subscribeAndMapQueries(component.id, component.data.map); subscribeAndMapQueries(component.id, component.data.map);
} }
if (component.data?.gql) {
getComposerStore(component.id).update((storeValue) => ({
...storeValue,
x: {
...storeValue.x,
...component.data.gql
}
}));
}
} }
getComposerStore(component.id).update((storeValue) => ({ getComposerStore(component.id).update((storeValue) => ({
...storeValue, ...storeValue,

View File

@ -1,58 +1,68 @@
<script lang="ts"> <script lang="ts">
import type { PageData } from '../test/$houdini'; import type { PageData } from '../test/$houdini';
import Composer from '$lib/core/refactor/composer.svelte'; import Composer from '$lib/core/refactor/Composer.svelte';
import { queryTodos } from '$lib/data/queryTodos'; import { queryTodos } from '$lib/data/queryTodos';
import { onMount } from 'svelte';
export let data: PageData; export let data: PageData;
let composer;
$: ({ queryTest } = data); $: ({ queryTest } = data);
let composer = { onMount(async () => {
id: 'ComposerParent', composer = await {
machine: { id: 'ComposerParent',
initial: 'NOTREADY', machine: {
states: { initial: 'NOTREADY',
NOTREADY: { states: {
on: { TOGGLE: 'READY' } NOTREADY: {
}, on: { TOGGLE: 'READY' }
READY: { },
on: { TOGGLE: 'NOTREADY' } READY: {
} on: { TOGGLE: 'NOTREADY' }
}
},
children: [
{
id: 'ComposerGraph',
component: 'ComposerGraph',
data: {
map: {
todos: queryTodos
} }
}, }
machine: { },
initial: 'LOADING', children: [
states: { {
LOADING: { id: 'ComposerGraph',
on: { component: 'ComposerGraph',
TOGGLE: { data: {
target: 'READY' map: {
} todos: queryTodos
}
}, },
READY: { gql: {
on: { test: await $queryTest.data
TOGGLE: { }
target: 'LOADING' },
machine: {
initial: 'LOADING',
states: {
LOADING: {
on: {
TOGGLE: {
target: 'READY'
}
}
},
READY: {
on: {
TOGGLE: {
target: 'LOADING'
}
} }
} }
} }
} }
} }
} ]
] };
}; });
</script> </script>
{JSON.stringify($queryTest.data, null, 2)} {#if $queryTest}
{JSON.stringify($queryTest.data, null, 2)}
{/if}
<Composer {composer} /> <Composer {composer} />