kesne / svelte-relay

Easily use GraphQL in Svelte, powered by the production-ready Relay runtime.
https://kesne.github.io/svelte-relay/
108 stars 5 forks source link

Possible API Change #1

Closed kesne closed 4 years ago

kesne commented 4 years ago

After thinking about this more, I think that potentially our query API could be simplified.

Rather than making the result of calling getQuery implement Promise<T> for the network fetch, and Readable<T> to access the data, we could make it Readable<Promise<T>>, where it will initially trigger a network fetch, and subsequently be updated with a resolved promise containing the updated store data.

We can also have the result implement Promise<T> if it is desirable to get data once, and not subscribe to store updates.

Example code

Before:

{#await query}
    <p>...waiting</p>
{:then}
    <ul>
        {#each $query.allFilms.edges as edge}
            <Movie movie={edge.node} />
        {/each}
{/await}

After:

{#await $query}
    <p>...waiting</p>
{:then data}
    <ul>
        {#each data.allFilms.edges as edge}
            <Movie movie={edge.node} />
        {/each}
{/await}

Downsides

I can think of two main downside of implementing this API:

Considerations