Files
twenty_crm/packages/twenty-chrome-extension/src/utils/requestDb.ts
Aditya Pimpalkar 5c5dcf5cb5 feat: check if company/person saved (chrome-extension) (#4280)
* add twenty icon

* rest api calls for company

* check if company exists

* refacto

* person/company saved call

* gql codegen init

* type defs

* build fix

* DB calls with gql codegen and apollo integration
2024-03-26 14:37:36 +01:00

35 lines
812 B
TypeScript

import { OperationVariables } from '@apollo/client';
import { DocumentNode } from 'graphql';
import getApolloClient from '~/utils/apolloClient';
export const callQuery = async <T>(
query: DocumentNode,
variables?: OperationVariables,
): Promise<T | null> => {
const client = await getApolloClient();
const { data, error } = await client.query<T>({ query, variables });
if (error) throw new Error(error.message);
if (data) return data;
return null;
};
export const callMutation = async <T>(
mutation: DocumentNode,
variables?: OperationVariables,
): Promise<T | null> => {
const client = await getApolloClient();
const { data, errors } = await client.mutate<T>({ mutation, variables });
if (errors) throw new Error(errors[0].message);
if (data) return data;
return null;
};