webapp/src/graphql/createGraphQLClient.ts

22 lines
655 B
TypeScript
Raw Normal View History

2024-02-04 11:25:21 +00:00
import { ClientOptions, Exchange, createClient, dedupExchange, fetchExchange } from '@urql/core'
2023-12-03 10:22:42 +00:00
import { devtoolsExchange } from '@urql/devtools'
import { isDev } from '../utils/config'
const exchanges: Exchange[] = [dedupExchange, fetchExchange]
if (isDev) {
exchanges.unshift(devtoolsExchange)
}
2024-02-04 09:03:15 +00:00
export const createGraphQLClient = (serviceName: string, token = '') => {
2023-12-03 10:22:42 +00:00
const options: ClientOptions = {
url: `https://${serviceName}.discours.io`,
maskTypename: true,
requestPolicy: 'cache-and-network',
fetchOptions: () => (token ? { headers: { Authorization: token } } : {}),
exchanges,
}
return createClient(options)
}