[2] fix graphql:codegen

This commit is contained in:
vchikalkin 2024-02-27 16:24:33 +03:00
parent c2d9093efe
commit 974dfb57a8
5 changed files with 52 additions and 74 deletions

View File

@ -1,6 +1,6 @@
overwrite: true
schema: './graphql/crm.schema.graphql'
documents: ['./**/!(*.{d,types}).{ts,tsx}', './**/.{js,jsx}', ./**/!(*.schema).graphql]
documents: [./**/!(*.schema).graphql]
generates:
./graphql/crm.types.ts:
plugins:

View File

@ -48,6 +48,7 @@ query GetLead($leadid: Uuid!) {
}
evo_okved
}
link
}
}
@ -61,6 +62,7 @@ query GetOpportunity($opportunityid: Uuid!) {
}
evo_okved
}
link
}
}
@ -107,6 +109,7 @@ query GetQuote($quoteId: Uuid!) {
evo_kasko_payer
evo_promotion
evo_sale_without_nds
link
}
}

File diff suppressed because one or more lines are too long

View File

@ -1,17 +1,31 @@
/* eslint-disable no-negated-condition */
import type { Elements } from '@/Components/Calculation/config/map/values';
import * as CRMTypes from '@/graphql/crm.types';
import type { ProcessContext } from '@/process/types';
import type { DocumentNode } from '@apollo/client';
import { gql } from '@apollo/client';
import { reaction } from 'mobx';
type LinkReactionParams = {
elementName: Elements;
entityName: string;
linkElementName: Elements;
query: DocumentNode;
variableName: string;
};
export default function reactions({ store, apolloClient }: ProcessContext) {
const { $calculation } = store;
/**
* При выборе Интереса, ЛС и Предложения скачиваем ссылку CRM
*/
function makeLinkReaction(elementName: Elements, linkElementName: Elements, query: DocumentNode) {
function makeLinkReaction({
elementName,
linkElementName,
query,
variableName,
entityName,
}: LinkReactionParams) {
reaction(
() => $calculation.element(elementName).getValue(),
(id) => {
@ -29,13 +43,13 @@ export default function reactions({ store, apolloClient }: ProcessContext) {
.query({
query,
variables: {
id,
[variableName]: id,
},
})
.then(({ data }) => {
clearTimeout(timeoutId);
if (data.entity?.link) {
$calculation.element(linkElementName).setValue(data.entity?.link);
if (data[entityName]?.link) {
$calculation.element(linkElementName).setValue(data[entityName]?.link);
}
})
.catch(() => {
@ -56,30 +70,27 @@ export default function reactions({ store, apolloClient }: ProcessContext) {
);
}
const QUERY_GET_LEAD_URL = gql`
query GetLeadUrl($id: Uuid!) {
entity: lead(leadid: $id) {
link
}
}
`;
makeLinkReaction('selectLead', 'linkLeadUrl', QUERY_GET_LEAD_URL);
makeLinkReaction({
elementName: 'selectLead',
entityName: 'lead',
linkElementName: 'linkLeadUrl',
query: CRMTypes.GetLeadDocument,
variableName: 'leadid',
});
const QUERY_GET_OPPORTUNITY_URL = gql`
query GetOpportunityUrl($id: Uuid!) {
entity: opportunity(opportunityid: $id) {
link
}
}
`;
makeLinkReaction('selectOpportunity', 'linkOpportunityUrl', QUERY_GET_OPPORTUNITY_URL);
makeLinkReaction({
elementName: 'selectOpportunity',
entityName: 'opportunity',
linkElementName: 'linkOpportunityUrl',
query: CRMTypes.GetOpportunityDocument,
variableName: 'opportunityid',
});
const QUERY_GET_QUOTE_URL = gql`
query GetQuoteUrl($id: Uuid!) {
entity: quote(quoteId: $id) {
link
}
}
`;
makeLinkReaction('selectQuote', 'linkQuoteUrl', QUERY_GET_QUOTE_URL);
makeLinkReaction({
elementName: 'selectQuote',
entityName: 'quote',
linkElementName: 'linkQuoteUrl',
query: CRMTypes.GetQuoteDocument,
variableName: 'quoteId',
});
}

14
pnpm-lock.yaml generated
View File

@ -6133,18 +6133,6 @@ packages:
ms: 2.1.3
dev: true
/debug@4.3.4:
resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==}
engines: {node: '>=6.0'}
peerDependencies:
supports-color: '*'
peerDependenciesMeta:
supports-color:
optional: true
dependencies:
ms: 2.1.2
dev: true
/debug@4.3.4(supports-color@5.5.0):
resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==}
engines: {node: '>=6.0'}
@ -10379,7 +10367,7 @@ packages:
chalk: 5.2.0
cli-truncate: 3.1.0
commander: 10.0.0
debug: 4.3.4
debug: 4.3.4(supports-color@5.5.0)
execa: 7.2.0
lilconfig: 2.1.0
listr2: 5.0.8