-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathUrqlContext.tsx
More file actions
26 lines (21 loc) · 861 Bytes
/
UrqlContext.tsx
File metadata and controls
26 lines (21 loc) · 861 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import React, { useContext } from 'react';
import { Provider, createClient, fetchExchange } from 'urql';
import { kitsuConfig } from '@/config/env';
import InvariantViolated from '@/errors/InvariantViolated';
import authExchange from '@/graphql/urql-exchanges/auth';
import cacheExchange from '@/graphql/urql-exchanges/cache';
import { SessionContext } from './SessionContext';
export default function UrqlContext({
children,
}: {
children: React.ReactNode;
}): JSX.Element {
const sessionContext = useContext(SessionContext);
if (!sessionContext) throw new InvariantViolated('SessionContext is missing');
const client = createClient({
suspense: true,
exchanges: [cacheExchange, authExchange(sessionContext), fetchExchange],
url: `${kitsuConfig.kitsuUrl}/api/graphql`,
});
return <Provider value={client}>{children}</Provider>;
}