From 5b14a1a75a4847930aa5ea96a5b2ecf4e1e8cf1c Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Mon, 23 Dec 2024 14:34:57 +0300 Subject: [PATCH] apps/bot: add function getClientWithToken --- apps/bot/src/api/query.ts | 6 ++---- apps/bot/src/apollo/client.ts | 6 ++++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/bot/src/api/query.ts b/apps/bot/src/api/query.ts index 9ca47ed..0698015 100644 --- a/apps/bot/src/api/query.ts +++ b/apps/bot/src/api/query.ts @@ -1,10 +1,8 @@ -import { createApolloClient } from '../apollo/client'; -import { getToken } from '../utils/jwt'; +import { getClientWithToken } from '../apollo/client'; import * as GQL from '@repo/graphql/types'; export async function createCustomer(variables: GQL.CreateCustomerMutationVariables) { - const token = await getToken(); - const { mutate } = createApolloClient({ token }); + const { mutate } = await getClientWithToken(); return mutate({ mutation: GQL.CreateCustomerDocument, diff --git a/apps/bot/src/apollo/client.ts b/apps/bot/src/apollo/client.ts index 0de2834..e583e75 100644 --- a/apps/bot/src/apollo/client.ts +++ b/apps/bot/src/apollo/client.ts @@ -1,4 +1,5 @@ import { env as environment } from '../config/env'; +import { getToken } from '../utils/jwt'; import { ApolloClient, InMemoryCache } from '@apollo/client/core'; type Parameters_ = { token: null | string | undefined }; @@ -14,3 +15,8 @@ export function createApolloClient(parameters?: Parameters_) { uri: environment.URL_GRAPHQL, }); } + +export async function getClientWithToken() { + const token = await getToken(); + return createApolloClient({ token }); +}