railbird-gql/graphql/client.tsx
2024-01-08 23:52:08 -07:00

34 lines
740 B
TypeScript

import React, { ReactNode } from "react";
import {
ApolloClient,
InMemoryCache,
ApolloProvider,
HttpLink,
from,
} from "@apollo/client";
import { API_URI } from "@env";
import { SHOT_FEATURES_FRAGMENT } from "./fragment/shot";
import { createFragmentRegistry } from "@apollo/client/cache";
type Props = {
children: ReactNode;
};
const ClientProvider: React.FC<Props> = ({ children }) => {
const httpLink = new HttpLink({
uri: API_URI,
});
const cache = new InMemoryCache({
fragments: createFragmentRegistry(SHOT_FEATURES_FRAGMENT),
});
const client = new ApolloClient({
link: from([httpLink]),
cache: cache,
});
return <ApolloProvider client={client}>{children}</ApolloProvider>;
};
export default ClientProvider;