graphql-codegen-apollo-next-ssr icon indicating copy to clipboard operation
graphql-codegen-apollo-next-ssr copied to clipboard

Cache results not changing even with fetch policy set to network-only or no-cache?

Open jean182 opened this issue 4 years ago • 1 comments

I'm having an issue using this library that whenever I change something in my backend, the next js app does not update with the new results(when refreshing the page) even if the fetch policy is network-only o no-cache, any ideas why this is happening, or is there some documentation on how to accomplish that.

import {ssrGetRanking, PageGetRankingComp} from 'generated/page'

import {GetServerSidePropsContext} from 'next'
import React from 'react'

import {withApollo} from 'withApollo'

const RankingPage: PageGetRankingComp = ({data, error}) => {
  // Comp logic goes here
}

export async function getServerSideProps(ctx: GetServerSidePropsContext) {
  return await ssrGetRanking.getServerPage({fetchPolicy: 'network-only'}, ctx)
}

export default withApollo(ssrGetRanking.withPage(() => ({}))(RankingPage))

I also try to add the fetch policy in the HOC wrap but then I notice that the component was having a delay with the data values because it displays undefined and after that the data is valid.

import {ssrGetRanking, PageGetRankingComp} from 'generated/page'

import {GetServerSidePropsContext} from 'next'
import React from 'react'

import {withApollo} from 'withApollo'

const RankingPage: PageGetRankingComp = ({data, error}) => {
  // Comp logic goes here
}

export async function getServerSideProps(ctx: GetServerSidePropsContext) {
  return await ssrGetRanking.getServerPage({fetchPolicy: 'network-only'}, ctx)
}

export default withApollo(
  ssrGetRanking.withPage(() => ({fetchPolicy: 'network-only'}))(RankingPage),
)

jean182 avatar Apr 22 '21 20:04 jean182

hi,

Not sure what's the cause of the issue without looking at the full example. This plugin doesn't affect the apollo cache, it only reads it.

the ApolloProvider should always create a new instance of the apolloClient when running on the server (on the client it can be a singleton).

You can see an example https://github.com/correttojs/graphql-codegen-apollo-next-ssr/blob/main/example/src/withApollo.tsx#L11

correttojs avatar Apr 25 '21 10:04 correttojs