diff --git a/apps/bot/src/index.ts b/apps/bot/src/index.ts index 7aa2189..b789740 100644 --- a/apps/bot/src/index.ts +++ b/apps/bot/src/index.ts @@ -1,5 +1,5 @@ import { env as environment } from './config/env'; -import { createCustomer, getCustomer } from '@repo/graphql/api/query'; +import { createCustomer, getCustomer } from '@repo/graphql/api'; import { Telegraf } from 'telegraf'; import { message } from 'telegraf/filters'; diff --git a/packages/graphql/api/auth.ts b/packages/graphql/api/auth.ts new file mode 100644 index 0000000..138348b --- /dev/null +++ b/packages/graphql/api/auth.ts @@ -0,0 +1,17 @@ +import { createApolloClient } from '../apollo/client'; +import { env as environment } from '../config/env'; +import * as GQL from '../types'; + +export async function login() { + const { mutate } = createApolloClient(); + + const response = await mutate({ + mutation: GQL.LoginDocument, + variables: { + identifier: environment.LOGIN_GRAPHQL, + password: environment.PASSWORD_GRAPHQL, + }, + }); + + return response; +} diff --git a/packages/graphql/api/query.ts b/packages/graphql/api/customer.ts similarity index 52% rename from packages/graphql/api/query.ts rename to packages/graphql/api/customer.ts index 8f4b4c5..2206662 100644 --- a/packages/graphql/api/query.ts +++ b/packages/graphql/api/customer.ts @@ -1,5 +1,4 @@ -import { createApolloClient, getClientWithToken } from '../apollo/client'; -import { env as environment } from '../config/env'; +import { getClientWithToken } from '../apollo/client'; import * as GQL from '../types'; export async function createCustomer(variables: GQL.CreateCustomerMutationVariables) { @@ -19,17 +18,3 @@ export async function getCustomer(variables: GQL.GetCustomerQueryVariables) { variables, }); } - -export async function login() { - const { mutate } = createApolloClient(); - - const response = await mutate({ - mutation: GQL.LoginDocument, - variables: { - identifier: environment.LOGIN_GRAPHQL, - password: environment.PASSWORD_GRAPHQL, - }, - }); - - return response; -} diff --git a/packages/graphql/api/index.ts b/packages/graphql/api/index.ts new file mode 100644 index 0000000..95c5dd4 --- /dev/null +++ b/packages/graphql/api/index.ts @@ -0,0 +1,2 @@ +export * from './auth'; +export * from './customer'; diff --git a/packages/graphql/apollo.config.js b/packages/graphql/apollo.config.js index dffc4a6..5d76f2c 100644 --- a/packages/graphql/apollo.config.js +++ b/packages/graphql/apollo.config.js @@ -1,7 +1,7 @@ /* eslint-disable no-undef */ module.exports = { client: { - includes: ['../../packages/graphql/query.graphql'], + includes: ['./operations/*.graphql'], service: { name: 'strapi', url: require('./config.cjs').url, diff --git a/packages/graphql/config/token.ts b/packages/graphql/config/token.ts index eb29fa1..deb26c2 100644 --- a/packages/graphql/config/token.ts +++ b/packages/graphql/config/token.ts @@ -1,4 +1,4 @@ -import { login } from '../api/query'; +import { login } from '../api'; import { isTokenExpired } from '../utils/jwt'; export const token: null | string = null; diff --git a/packages/graphql/graphql.config.cjs b/packages/graphql/graphql.config.cjs index bcaa708..a9c2fad 100644 --- a/packages/graphql/graphql.config.cjs +++ b/packages/graphql/graphql.config.cjs @@ -1,8 +1,8 @@ /** @type {import('@graphql-codegen/cli').CodegenConfig} */ module.exports = { - documents: './query.graphql', + documents: ['./operations/*.graphql'], generates: { - './types.ts': { + './types/operations.generated.ts': { config: { avoidOptionals: true, onlyOperationTypes: true, diff --git a/packages/graphql/operations/auth.graphql b/packages/graphql/operations/auth.graphql new file mode 100644 index 0000000..4822a87 --- /dev/null +++ b/packages/graphql/operations/auth.graphql @@ -0,0 +1,14 @@ +mutation Register($identifier: String!, $password: String!, $email: String!) { + register(input: { username: $identifier, password: $password, email: $email }) { + jwt + user { + username + } + } +} + +mutation Login($identifier: String!, $password: String!) { + login(input: { identifier: $identifier, password: $password }) { + jwt + } +} diff --git a/packages/graphql/query.graphql b/packages/graphql/operations/customer.graphql similarity index 53% rename from packages/graphql/query.graphql rename to packages/graphql/operations/customer.graphql index f2b4e29..f438738 100644 --- a/packages/graphql/query.graphql +++ b/packages/graphql/operations/customer.graphql @@ -1,18 +1,3 @@ -mutation Register($identifier: String!, $password: String!, $email: String!) { - register(input: { username: $identifier, password: $password, email: $email }) { - jwt - user { - username - } - } -} - -mutation Login($identifier: String!, $password: String!) { - login(input: { identifier: $identifier, password: $password }) { - jwt - } -} - mutation CreateCustomer($name: String!, $telegramId: Long!, $phone: String!) { createCustomer(data: { name: $name, telegramId: $telegramId, phone: $phone, role: client }) { documentId diff --git a/packages/graphql/types/index.ts b/packages/graphql/types/index.ts new file mode 100644 index 0000000..6554672 --- /dev/null +++ b/packages/graphql/types/index.ts @@ -0,0 +1 @@ +export * from './operations.generated'; diff --git a/packages/graphql/types.ts b/packages/graphql/types/operations.generated.ts similarity index 100% rename from packages/graphql/types.ts rename to packages/graphql/types/operations.generated.ts