timhall / svelte-apollo

Svelte integration for Apollo GraphQL
MIT License
947 stars 68 forks source link

Discussion: Hydrate client in Sapper with less boilerplate #36

Closed justinmoon closed 3 years ago

justinmoon commented 4 years ago

The example from the docs mostly works for me:

<script context="module">
  ...
  export async function preload() {
    return {
      cache: await client.query({   ...   })
    }
  }
</script>

<script>
  ...
  export let cache;
  restore(client, EVERYTHING, cache.data);
  setClient(client);
  ...
</script>
...

But it's very tiresome to include the restore and setClient calls on every page. Is it possible to define some kind of middleware which instantiates a client-side ApolloClient() instance and hydrates it from cache.data if the preload function returned a cache attribute?

I don't know svelte / sapper well enough to know if this is possible, but it seems like it should be!

justinmoon commented 4 years ago

Here's a related issue in Sapper repo. The author made a PR that hasn't received any review in 6 months, which is concerning ...

timhall commented 3 years ago

Will track this in #9