railbird-gql/graphql/client.tsx

34 lines
740 B
TypeScript
Raw Normal View History

2024-01-06 23:58:54 -07:00
import React, { ReactNode } from "react";
2024-01-06 23:48:47 -07:00
import {
ApolloClient,
InMemoryCache,
ApolloProvider,
HttpLink,
from,
} from "@apollo/client";
import { API_URI } from "@env";
2024-01-08 22:31:08 -07:00
import { SHOT_FEATURES_FRAGMENT } from "./fragment/shot";
import { createFragmentRegistry } from "@apollo/client/cache";
2024-01-06 23:48:47 -07:00
2024-01-06 23:58:54 -07:00
type Props = {
children: ReactNode;
};
const ClientProvider: React.FC<Props> = ({ children }) => {
const httpLink = new HttpLink({
uri: API_URI,
});
2024-01-08 22:31:08 -07:00
const cache = new InMemoryCache({
fragments: createFragmentRegistry(SHOT_FEATURES_FRAGMENT),
});
2024-01-06 23:48:47 -07:00
2024-01-06 23:58:54 -07:00
const client = new ApolloClient({
link: from([httpLink]),
2024-01-08 22:31:08 -07:00
cache: cache,
2024-01-06 23:58:54 -07:00
});
2024-01-06 23:48:47 -07:00
return <ApolloProvider client={client}>{children}</ApolloProvider>;
};
2024-01-06 23:58:54 -07:00
export default ClientProvider;