Files
worldcup/lib/graphql/client.ts
T
valknar de03dfeadb fix: suppress Apollo cache warnings for Match.team1 / Match.team2
Different queries fetch Team with different field sets (some include slug,
others don't). merge: true tells InMemoryCache to combine fields rather
than replace, avoiding the "cache data may be lost" warning.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-14 22:18:47 +02:00

25 lines
754 B
TypeScript

'use client'
import { ApolloClient, InMemoryCache, HttpLink } from '@apollo/client/core'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let client: InstanceType<typeof ApolloClient> | null = null
function createClient() {
return new ApolloClient({
link: new HttpLink({ uri: '/api/graphql' }),
cache: new InMemoryCache({
typePolicies: {
Team: { fields: { stats: { merge: true } } },
Match: { fields: { team1: { merge: true }, team2: { merge: true } } },
},
}),
defaultOptions: { watchQuery: { fetchPolicy: 'cache-and-network' } },
})
}
export function getApolloClient() {
if (typeof window === 'undefined') return createClient()
if (!client) client = createClient()
return client
}