timhall / svelte-apollo

Svelte integration for Apollo GraphQL
MIT License
946 stars 67 forks source link

refetch never hits cache #40

Open cdock1029 opened 4 years ago

cdock1029 commented 4 years ago

As per the readme for fetching data on variables change..

<script>
  import { getClient, query } from 'svelte-apollo';
  import { SEARCH_BY_AUTHOR } from './queries';

  export let author;
  let search = '';

  const client = getClient();

  // The books query isn't executed until variables are given via refetch
  // allowing svelte's reactive declarations to be used for variables
  const books = query(client, {
    query: SEARCH_BY_AUTHOR,
    variables: { author, search }
  });

  // `books` is refetched when author or search change
  $: books.refetch({ author, search });
</script>

...I can never get queries setup this way to pull data from cache, even the initial query.

But this works instead:

<script>
  import { getClient, query } from 'svelte-apollo';
  import { SEARCH_BY_AUTHOR } from './queries';

  export let author;
  let search = '';

  const client = getClient();

  $: books = query(client, {
    query: SEARCH_BY_AUTHOR,
    variables: { author, search }
  });
</script>

Thoughts? Don't see any downside so far.

frederikhors commented 4 years ago

Yes, but I can't use it because of https://github.com/timhall/svelte-apollo/issues/40.

Do you have the same problem, right?

UPDATE

I meant https://github.com/timhall/svelte-apollo/issues/19.

cdock1029 commented 4 years ago

@frederikhors I don't understand

frederikhors commented 4 years ago

Are you having this problem in your app https://github.com/timhall/svelte-apollo/issues/19?

EddyVinck commented 4 years ago

I just ran into this as well. someQuery.refetch() seems to do nothing to the cache. The request is made to the server as I can see in my developer tools, but nothing else seems to happen after that.