task_receipts/client/src/graphql/client.ts
2025-06-14 15:57:24 -05:00

38 lines
980 B
TypeScript

import { ApolloClient, InMemoryCache, createHttpLink, from } from '@apollo/client';
import { onError } from '@apollo/client/link/error';
const httpLink = createHttpLink({
uri: 'http://localhost:4000/graphql',
});
const errorLink = onError(({ graphQLErrors, networkError }) => {
if (graphQLErrors)
graphQLErrors.forEach(({ message, locations, path }) =>
console.error(
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
)
);
if (networkError) console.error(`[Network error]: ${networkError}`);
});
export const client = new ApolloClient({
link: from([errorLink, httpLink]),
cache: new InMemoryCache({
typePolicies: {
Query: {
fields: {
groups: {
merge(_, incoming) {
return incoming;
},
},
tasks: {
merge(_, incoming) {
return incoming;
},
},
},
},
},
}),
});