2023-05-31 16:53:42 +03:00

46 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import getUrls from './urls';
import { ApolloLink, HttpLink } from '@apollo/client';
const { URL_CRM_GRAPHQL } = getUrls();
const modifyDataLink = new ApolloLink((operation, forward) => {
const context = operation?.getContext();
return forward(operation).map((response) => {
if (!context?.disableModify) {
if (Object.keys(response?.data).includes('evo_addproduct_types')) {
response.data.evo_addproduct_types = response.data.evo_addproduct_types.map((x) => ({
...x,
label: `${x.label} (${x.evo_graph_price} руб.)`,
}));
}
if (Object.keys(response?.data).includes('evo_equipments')) {
response.data.evo_equipments = response.data.evo_equipments.map((x) => ({
...x,
label: `${x.label} (${x.evo_start_production_year})`,
}));
}
if (operation.operationName === 'GetInsuranceCompanies') {
response.data.accounts = response.data.accounts.map((x) => {
const substring = x.label.match(/"(.+)"/u);
return {
...x,
label: substring ? substring[1].replaceAll('"', '').trim() : x.label,
};
});
}
}
return response;
});
});
const httpLink = new HttpLink({
uri: URL_CRM_GRAPHQL,
});
export const link = modifyDataLink.concat(httpLink);