2026-06-14 15:36:44 +02:00
|
|
|
'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' }),
|
2026-06-14 21:12:13 +02:00
|
|
|
cache: new InMemoryCache({
|
|
|
|
|
typePolicies: {
|
|
|
|
|
Team: { fields: { stats: { merge: true } } },
|
2026-06-14 22:18:47 +02:00
|
|
|
Match: { fields: { team1: { merge: true }, team2: { merge: true } } },
|
2026-06-14 21:12:13 +02:00
|
|
|
},
|
|
|
|
|
}),
|
2026-06-14 15:36:44 +02:00
|
|
|
defaultOptions: { watchQuery: { fetchPolicy: 'cache-and-network' } },
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getApolloClient() {
|
|
|
|
|
if (typeof window === 'undefined') return createClient()
|
|
|
|
|
if (!client) client = createClient()
|
|
|
|
|
return client
|
|
|
|
|
}
|