This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
mobile-app/src/libs/graphql/createClient.ts

37 lines
922 B
TypeScript

import {
ApolloClient,
InMemoryCache,
NormalizedCacheObject,
ApolloLink,
HttpLink,
} from '@apollo/client';
import { onError } from '@apollo/client/link/error';
const createClient = (uri: string): ApolloClient<NormalizedCacheObject> => {
return new ApolloClient({
queryDeduplication: true,
cache: new InMemoryCache(),
link: ApolloLink.from([
onError(({ graphQLErrors, networkError }) => {
if (__DEV__) {
if (graphQLErrors) {
graphQLErrors.forEach(({ message, locations, path }) =>
console.log(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`,
),
);
}
if (networkError) {
console.log(`[Network error]: ${networkError}`);
}
}
}),
new HttpLink({
uri,
}),
]),
});
};
export default createClient;