nuxt-modules / apollo

Nuxt.js module to use Vue-Apollo. The Apollo integration for GraphQL.
https://apollo.nuxtjs.org
MIT License
956 stars 198 forks source link

New data not available on direct access when using SSR #428

Open SoftCreatR opened 2 years ago

SoftCreatR commented 2 years ago

First of all: The page https://cmty.app/nuxt/issues/new?repo=apollo-module returns an error, so I have to directly create the issue here.

We are using Nuxt 2.15.8, and 4.0.1-rc.5 of the apollo module. So far, everything works fine, however, for several reasons (e.g. https://github.com/nuxt/nuxt.js/issues/10307), we need to run the frontend with SSR enabled.

The problem we're experiencing is, that on direct access, apollo doesn't fetch new data from the backend (Strapi 4), so changes won't be reflected in the frontend. However, when navigating to a sub-page via Nuxt Link, a call against the Backend is being performed and new/changed data is visible.

For example, if I visit https://example.com/pageA directly, no call against the backend is made. Navigating from here to https://example.com/pageB performs a call to the backend and displays the modified information. Navigating back from here to https://example.com/pageA doesn't perform a call either.

But if I visit https://example.com/pageB, no call against the backend is made. Navigating from here to https://example.com/pageA performs a call to the backend and displays the modified information.

The code we're using is dead simple:

import exampleQuery from '@/apollo/queries/example'

export default {
  data () {
    return {
      example: {}
    }
  },
  apollo: {
    example: {
      prefetch: true,
      query: exampleQuery
    }
  }
}

And the nuxt.config.js part:

    // https://github.com/nuxt-community/apollo-module
    ['@nuxtjs/apollo', {
      clientConfigs: {
        default: {
          httpEndpoint: `${process.env.BACKEND_API}/graphql`
        }
      }
    }],

What could be the issue? Isn't this module compatible with SSR?

lustremedia commented 2 years ago

Look into caching. rc5 has several issues when it comes to SSR. Someone recommend to go back to 4.0.1-rc1 which seems to be a bit more stable ...