Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue Apollo Composable 4, prefetch not working in ssr mode #1100

Open
tcastelly opened this issue Nov 15, 2020 · 4 comments
Open

Vue Apollo Composable 4, prefetch not working in ssr mode #1100

tcastelly opened this issue Nov 15, 2020 · 4 comments

Comments

@tcastelly
Copy link

tcastelly commented Nov 15, 2020

Describe the bug
When VueJS 3 application is running in ssr mode, the prefetch apollo is not working.

To Reproduce

export default defineComponent({
  name: 'Graphql',
  setup() {
    const { result } = useQuery(DEMO_QUERY, {}, {
      prefetch: true,
    });

    return {
      result,
    };
  },
});

My workaround is to add a promise in serverPrefetch to wait values:

export default defineComponent({
  name: 'Graphql',
  setup() {
    const { result, loading } = useQuery(DEMO_QUERY, {}, {
      prefetch: true,
    });

    return {
      result,
      loading,
    };
  },
  async serverPrefetch() {
    return new Promise((resolve) => {
      watch(
        () => this.loading,
        () => resolve(),
      );
    });
  },
});

Link to a project:
https://github.com/shenron/vue3-example-ssr/blob/apollo/src/pages/Graphql.vue

Expected behavior
In my mind, because I set prefetch to true, the query should be resolved before the renderToString.

Versions
vue: 3.0.2
edit: apollo-client: 4.0.0-alpha.12
@apollo/client: 3.2.0
@vue/apollo-composable: 4.0.0-alpha.12

@dmitry
Copy link

dmitry commented Nov 20, 2020

Where did you found apollo-client 4.0.0? Probably you mean vue-apollo 4.0.0? In case of that what apollo-client version do you have? It should be something around 3.2 or 3.3. In my case everything works with vue-apollo v3.0.5 + apollo-client v3.2.6.

@tcastelly
Copy link
Author

I'm sorry I mix-up apollo-client and @vue/apollo-composable versions ...

(about vue-apollo-composable I patched like this: #1081 (comment))

{
    "@vue/apollo-composable": "file:vue-apollo-composable-v4.0.0-alpha.12.tgz",
    "apollo-client": "^2.6.10",
    "vue": "^3.0.2",
  },

I replaced apollo-client by @apollo/client@3.2.0 but I still have the same problem. Because I use vue-apollo-composable, I guess I don't need vue-apollo client?

@tcastelly tcastelly changed the title Vue Apollo 4, prefetch not working in ssr mode Vue Apollo Composable 4, prefetch not working in ssr mode Nov 20, 2020
@frandiox
Copy link
Contributor

frandiox commented Aug 16, 2021

@iamandrewluca
Copy link
Contributor

I think this is fixed in the latest alpha versions. vm.$isServer is not used anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants