enable cache in apollo client

This commit is contained in:
Chika 2020-12-08 15:02:07 +03:00
parent f490244f38
commit e169fa9bf7
3 changed files with 8 additions and 14 deletions

View File

@ -2,7 +2,7 @@
"name": "evo_calculator", "name": "evo_calculator",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@apollo/client": "^3.2.5", "@apollo/client": "^3.3.4",
"@babel/code-frame": "^7.10.4", "@babel/code-frame": "^7.10.4",
"@babel/helper-split-export-declaration": "^7.11.0", "@babel/helper-split-export-declaration": "^7.11.0",
"@craco/craco": "^5.8.0", "@craco/craco": "^5.8.0",

View File

@ -1,19 +1,10 @@
import { ApolloClient, InMemoryCache, HttpLink } from '@apollo/client'; import { ApolloClient, InMemoryCache } from '@apollo/client';
import { getServerUrl } from 'client/common/urls'; import { getServerUrl } from 'client/common/urls';
import { CRM_URL, CRM_PROXY_URL } from 'core/constants/urls'; import { CRM_PROXY_URL } from 'core/constants/urls';
export default new ApolloClient({ export default new ApolloClient({
uri: CRM_URL, uri: getServerUrl('/proxy', CRM_PROXY_URL),
cache: new InMemoryCache(), cache: new InMemoryCache(),
link: new HttpLink({
uri: getServerUrl('/proxy', CRM_PROXY_URL),
}),
defaultOptions: {
query: {
fetchPolicy: 'no-cache',
errorPolicy: 'all',
},
},
}); });

View File

@ -13,6 +13,7 @@ import { TEntities } from 'core/types/Entities/crmEntityNames';
import { isPlural, singular } from 'pluralize'; import { isPlural, singular } from 'pluralize';
import client from './client'; import client from './client';
import { convertEntityToOption } from './tools/entity'; import { convertEntityToOption } from './tools/entity';
import { cloneDeep } from 'lodash';
export default class { export default class {
static crmgqlquery = ({ static crmgqlquery = ({
@ -30,7 +31,9 @@ export default class {
if (!res.data || res.errors) { if (!res.data || res.errors) {
reject(res.error || res.errors); reject(res.error || res.errors);
} }
let resEntities: TEntities<TCRMEntity | TCRMEntity[]> = res.data; let resEntities: TEntities<TCRMEntity | TCRMEntity[]> = cloneDeep(
res.data,
);
Object.keys(resEntities).forEach(targetName => { Object.keys(resEntities).forEach(targetName => {
const targetEnt: TCRMEntity | TCRMEntity[] = const targetEnt: TCRMEntity | TCRMEntity[] =