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

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

Open
jean182 opened this issue Apr 22, 2021 · 1 comment

Comments

@jean182
Copy link

jean182 commented Apr 22, 2021

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),
)
@correttojs
Copy link
Owner

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

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

No branches or pull requests

2 participants