wgm-swap-components
Version:
A React component library for token swap interfaces
51 lines (50 loc) • 1.59 kB
JavaScript
import { ApolloClient, InMemoryCache, createHttpLink, from } from '@apollo/client';
import { onError } from '@apollo/client/link/error';
import { GRAPHQL_API_URL, GRAPHQL_API_URL_V2 } from '../constants';
// Error handling link
var errorLink = onError(function (_a) {
var graphQLErrors = _a.graphQLErrors, networkError = _a.networkError, operation = _a.operation, forward = _a.forward;
if (graphQLErrors) {
graphQLErrors.forEach(function (_a) {
var message = _a.message, locations = _a.locations, path = _a.path;
return console.error("[GraphQL error]: Message: ".concat(message, ", Location: ").concat(locations, ", Path: ").concat(path));
});
}
if (networkError) {
console.error("[Network error]: ".concat(networkError));
}
});
// HTTP link for primary API
var httpLink = createHttpLink({
uri: GRAPHQL_API_URL,
});
// HTTP link for V2 API
var httpLinkV2 = createHttpLink({
uri: GRAPHQL_API_URL_V2,
});
// Apollo Client for primary API
export var apolloClient = new ApolloClient({
link: from([errorLink, httpLink]),
cache: new InMemoryCache(),
defaultOptions: {
watchQuery: {
errorPolicy: 'all',
},
query: {
errorPolicy: 'all',
},
},
});
// Apollo Client for V2 API
export var apolloClientV2 = new ApolloClient({
link: from([errorLink, httpLinkV2]),
cache: new InMemoryCache(),
defaultOptions: {
watchQuery: {
errorPolicy: 'all',
},
query: {
errorPolicy: 'all',
},
},
});