prevent apollo caching on the server
This commit is contained in:
parent
5746160893
commit
de863021f9
|
@ -13,7 +13,7 @@ import { getPrice } from '../components/price'
|
|||
|
||||
export default async function getSSRApolloClient (req, me = null) {
|
||||
const session = req && await getSession({ req })
|
||||
return new ApolloClient({
|
||||
const client = new ApolloClient({
|
||||
ssrMode: true,
|
||||
link: new SchemaLink({
|
||||
schema: makeExecutableSchema({
|
||||
|
@ -31,6 +31,8 @@ export default async function getSSRApolloClient (req, me = null) {
|
|||
}),
|
||||
cache: new InMemoryCache()
|
||||
})
|
||||
await client.clearStore()
|
||||
return client
|
||||
}
|
||||
|
||||
export function getGetServerSideProps (query, variables = null, notFoundFunc, requireVar) {
|
||||
|
|
|
@ -19,8 +19,19 @@ function isFirstPage (cursor, existingThings) {
|
|||
}
|
||||
|
||||
export default function getApolloClient () {
|
||||
global.apolloClient ||= new ApolloClient({
|
||||
link: new HttpLink({ uri: '/api/graphql' }),
|
||||
if (typeof window === 'undefined') {
|
||||
const client = getClient(`${process.env.SELF_URL}/api/graphql`)
|
||||
client.clearStore()
|
||||
return client
|
||||
} else {
|
||||
global.apolloClient ||= getClient('/api/graphql')
|
||||
return global.apolloClient
|
||||
}
|
||||
}
|
||||
|
||||
function getClient (uri) {
|
||||
return new ApolloClient({
|
||||
link: new HttpLink({ uri }),
|
||||
cache: new InMemoryCache({
|
||||
typePolicies: {
|
||||
Query: {
|
||||
|
@ -201,6 +212,4 @@ export default function getApolloClient () {
|
|||
}
|
||||
}
|
||||
})
|
||||
|
||||
return global.apolloClient
|
||||
}
|
||||
|
|
|
@ -62,7 +62,7 @@ function MyApp ({ Component, pageProps: { session, ...props } }) {
|
|||
ssr data
|
||||
*/
|
||||
const { apollo, data, me, price } = props
|
||||
if (typeof window !== 'undefined' && apollo && data) {
|
||||
if (apollo && data) {
|
||||
client.writeQuery({
|
||||
query: gql`${apollo.query}`,
|
||||
data: data,
|
||||
|
|
|
@ -22,12 +22,12 @@ async function work () {
|
|||
cache: new InMemoryCache(),
|
||||
defaultOptions: {
|
||||
watchQuery: {
|
||||
fetchPolicy: 'network-only',
|
||||
nextFetchPolicy: 'network-only'
|
||||
fetchPolicy: 'no-cache',
|
||||
nextFetchPolicy: 'no-cache'
|
||||
},
|
||||
query: {
|
||||
fetchPolicy: 'network-only',
|
||||
nextFetchPolicy: 'network-only'
|
||||
fetchPolicy: 'no-cache',
|
||||
nextFetchPolicy: 'no-cache'
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue