Files
worldcup/lib/graphql/client.ts
T

20 lines
583 B
TypeScript
Raw Normal View History

'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(),
defaultOptions: { watchQuery: { fetchPolicy: 'cache-and-network' } },
})
}
export function getApolloClient() {
if (typeof window === 'undefined') return createClient()
if (!client) client = createClient()
return client
}