From 5d8b2ffc6b7eb6e028d4744afb3e90b05798fb8d Mon Sep 17 00:00:00 2001 From: vchikalkin Date: Mon, 23 Dec 2024 19:07:25 +0300 Subject: [PATCH] move all graphql functional to packages/graphql --- apps/bot/package.json | 10 +---- apps/bot/src/config/env.ts | 3 -- apps/bot/src/index.ts | 2 +- apps/bot/tsconfig.json | 2 +- apps/web/package.json | 6 +-- .../bot/src => packages/graphql}/api/query.ts | 2 +- .../src => packages/graphql}/apollo/client.ts | 0 packages/graphql/config/env.ts | 10 +++++ .../src => packages/graphql}/config/token.ts | 0 packages/graphql/package.json | 16 +++++--- packages/graphql/tsconfig.json | 4 +- .../graphql}/utils/jwt.test.ts | 2 +- .../bot/src => packages/graphql}/utils/jwt.ts | 0 pnpm-lock.yaml | 40 ++++++++++--------- 14 files changed, 55 insertions(+), 42 deletions(-) rename {apps/bot/src => packages/graphql}/api/query.ts (95%) rename {apps/bot/src => packages/graphql}/apollo/client.ts (100%) create mode 100644 packages/graphql/config/env.ts rename {apps/bot/src => packages/graphql}/config/token.ts (100%) rename {apps/bot/src => packages/graphql}/utils/jwt.test.ts (98%) rename {apps/bot/src => packages/graphql}/utils/jwt.ts (100%) diff --git a/apps/bot/package.json b/apps/bot/package.json index 67df8a7..fb099bc 100644 --- a/apps/bot/package.json +++ b/apps/bot/package.json @@ -10,12 +10,9 @@ "start": "node dist/src/index.js", "dev": "dotenv -e ../../.env.local tsx watch src/index.ts", "lint": "eslint", - "lint-staged": "lint-staged", - "test:unit": "vitest" + "lint-staged": "lint-staged" }, "dependencies": { - "@apollo/client": "catalog:", - "jsonwebtoken": "catalog:", "telegraf": "catalog:", "zod": "catalog:" }, @@ -24,14 +21,11 @@ "@repo/graphql": "workspace:*", "@repo/lint-staged-config": "workspace:*", "@repo/typescript-config": "workspace:*", - "@types/jsonwebtoken": "catalog:", "@types/node": "catalog:", "dotenv-cli": "catalog:", "lint-staged": "catalog:", "rimraf": "catalog:", "tsx": "catalog:", - "typescript": "catalog:", - "vite-tsconfig-paths": "catalog:", - "vitest": "catalog:" + "typescript": "catalog:" } } diff --git a/apps/bot/src/config/env.ts b/apps/bot/src/config/env.ts index 688f1e8..b783b6b 100644 --- a/apps/bot/src/config/env.ts +++ b/apps/bot/src/config/env.ts @@ -3,9 +3,6 @@ import { z } from 'zod'; export const envSchema = z.object({ BOT_TOKEN: z.string(), - LOGIN_GRAPHQL: z.string(), - PASSWORD_GRAPHQL: z.string(), - URL_GRAPHQL: z.string(), }); export const env = envSchema.parse(process.env); diff --git a/apps/bot/src/index.ts b/apps/bot/src/index.ts index 3b680f6..7aa2189 100644 --- a/apps/bot/src/index.ts +++ b/apps/bot/src/index.ts @@ -1,5 +1,5 @@ -import { createCustomer, getCustomer } from './api/query'; import { env as environment } from './config/env'; +import { createCustomer, getCustomer } from '@repo/graphql/api/query'; import { Telegraf } from 'telegraf'; import { message } from 'telegraf/filters'; diff --git a/apps/bot/tsconfig.json b/apps/bot/tsconfig.json index bb656f2..8ca3db9 100644 --- a/apps/bot/tsconfig.json +++ b/apps/bot/tsconfig.json @@ -11,6 +11,6 @@ "@/*": ["./*"] } }, - "include": ["."], + "include": [".", "../../packages/graphql/config", "../../packages/graphql/utils", "../../packages/graphql/apollo", "../../packages/graphql/api"], "exclude": ["dist", "build", "node_modules"] } diff --git a/apps/web/package.json b/apps/web/package.json index 711b34f..a85489f 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -1,10 +1,10 @@ { "name": "web", - "version": "0.1.0", + "version": "0.0.0", "type": "module", "private": true, "scripts": { - "dev": "next dev --turbopack", + "dev": "dotenv -e ../../.env.local next dev --turbopack", "build": "next build", "start": "next start", "lint": "next lint", @@ -14,7 +14,6 @@ "test:e2e": "playwright test" }, "dependencies": { - "@apollo/client": "catalog:", "@repo/ui": "workspace:*", "@telegram-apps/sdk-react": "catalog:", "graphql": "catalog:", @@ -36,6 +35,7 @@ "@types/react-dom": "catalog:", "@vitejs/plugin-react": "catalog:", "autoprefixer": "catalog:", + "dotenv-cli": "catalog:", "eruda": "catalog:", "jsdom": "catalog:", "lint-staged": "catalog:", diff --git a/apps/bot/src/api/query.ts b/packages/graphql/api/query.ts similarity index 95% rename from apps/bot/src/api/query.ts rename to packages/graphql/api/query.ts index 19f0241..8f4b4c5 100644 --- a/apps/bot/src/api/query.ts +++ b/packages/graphql/api/query.ts @@ -1,6 +1,6 @@ import { createApolloClient, getClientWithToken } from '../apollo/client'; import { env as environment } from '../config/env'; -import * as GQL from '@repo/graphql/types'; +import * as GQL from '../types'; export async function createCustomer(variables: GQL.CreateCustomerMutationVariables) { const { mutate } = await getClientWithToken(); diff --git a/apps/bot/src/apollo/client.ts b/packages/graphql/apollo/client.ts similarity index 100% rename from apps/bot/src/apollo/client.ts rename to packages/graphql/apollo/client.ts diff --git a/packages/graphql/config/env.ts b/packages/graphql/config/env.ts new file mode 100644 index 0000000..91482f2 --- /dev/null +++ b/packages/graphql/config/env.ts @@ -0,0 +1,10 @@ +/* eslint-disable unicorn/prevent-abbreviations */ +import { z } from 'zod'; + +export const envSchema = z.object({ + LOGIN_GRAPHQL: z.string(), + PASSWORD_GRAPHQL: z.string(), + URL_GRAPHQL: z.string(), +}); + +export const env = envSchema.parse(process.env); diff --git a/apps/bot/src/config/token.ts b/packages/graphql/config/token.ts similarity index 100% rename from apps/bot/src/config/token.ts rename to packages/graphql/config/token.ts diff --git a/packages/graphql/package.json b/packages/graphql/package.json index 831a7dc..12d57e1 100644 --- a/packages/graphql/package.json +++ b/packages/graphql/package.json @@ -3,19 +3,25 @@ "version": "0.0.0", "license": "MIT", "type": "module", - "exports": { - "./types": "./types.ts" - }, "scripts": { - "graphql:codegen": "graphql-codegen --config graphql.config.cjs" + "graphql:codegen": "graphql-codegen --config graphql.config.cjs", + "test:unit": "vitest" + }, + "dependencies": { + "@apollo/client": "catalog:", + "jsonwebtoken": "catalog:", + "zod": "catalog:" }, "devDependencies": { "graphql": "catalog:", "@repo/typescript-config": "workspace:*", + "@types/jsonwebtoken": "catalog:", "@graphql-codegen/cli": "catalog:", "@graphql-codegen/typed-document-node": "catalog:", "@graphql-codegen/typescript": "catalog:", "@graphql-codegen/typescript-operations": "catalog:", - "@graphql-typed-document-node/core": "catalog:" + "@graphql-typed-document-node/core": "catalog:", + "vite-tsconfig-paths": "catalog:", + "vitest": "catalog:" } } diff --git a/packages/graphql/tsconfig.json b/packages/graphql/tsconfig.json index 28c53a1..c106372 100644 --- a/packages/graphql/tsconfig.json +++ b/packages/graphql/tsconfig.json @@ -4,7 +4,9 @@ "baseUrl": ".", "paths": { "@/*": ["./*"] - } + }, + "moduleResolution": "bundler", + "module": "ES2022" }, "include": ["."], "exclude": ["dist", "build", "node_modules"] diff --git a/apps/bot/src/utils/jwt.test.ts b/packages/graphql/utils/jwt.test.ts similarity index 98% rename from apps/bot/src/utils/jwt.test.ts rename to packages/graphql/utils/jwt.test.ts index 77fbbe4..34408ef 100644 --- a/apps/bot/src/utils/jwt.test.ts +++ b/packages/graphql/utils/jwt.test.ts @@ -1,5 +1,5 @@ /* eslint-disable unicorn/consistent-function-scoping */ -import { isTokenExpired } from './jwt'; +import { isTokenExpired } from './jwt.js'; import * as jwt from 'jsonwebtoken'; import { afterEach, describe, expect, it, vi } from 'vitest'; diff --git a/apps/bot/src/utils/jwt.ts b/packages/graphql/utils/jwt.ts similarity index 100% rename from apps/bot/src/utils/jwt.ts rename to packages/graphql/utils/jwt.ts diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 38d82d0..72aed87 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -173,12 +173,6 @@ importers: apps/bot: dependencies: - '@apollo/client': - specifier: 'catalog:' - version: 3.12.4(@types/react@19.0.1)(graphql-ws@5.16.0(graphql@16.9.0))(graphql@16.9.0)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) - jsonwebtoken: - specifier: 'catalog:' - version: 9.0.2 telegraf: specifier: 'catalog:' version: 4.16.3 @@ -198,9 +192,6 @@ importers: '@repo/typescript-config': specifier: workspace:* version: link:../../packages/typescript-config - '@types/jsonwebtoken': - specifier: 'catalog:' - version: 9.0.7 '@types/node': specifier: 'catalog:' version: 20.17.8 @@ -219,18 +210,9 @@ importers: typescript: specifier: 'catalog:' version: 5.7.2 - vite-tsconfig-paths: - specifier: 'catalog:' - version: 5.1.4(typescript@5.7.2)(vite@5.4.11(@types/node@20.17.8)) - vitest: - specifier: 'catalog:' - version: 2.1.8(@types/node@20.17.8)(jsdom@25.0.1) apps/web: dependencies: - '@apollo/client': - specifier: 'catalog:' - version: 3.12.4(@types/react@19.0.1)(graphql-ws@5.16.0(graphql@16.9.0))(graphql@16.9.0)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) '@repo/ui': specifier: workspace:* version: link:../../packages/ui @@ -289,6 +271,9 @@ importers: autoprefixer: specifier: 'catalog:' version: 10.4.20(postcss@8.4.49) + dotenv-cli: + specifier: 'catalog:' + version: 7.4.4 eruda: specifier: 'catalog:' version: 3.4.1 @@ -330,6 +315,16 @@ importers: version: 2.3.2(eslint@9.15.0(jiti@2.4.1)) packages/graphql: + dependencies: + '@apollo/client': + specifier: 'catalog:' + version: 3.12.4(@types/react@19.0.1)(graphql-ws@5.16.0(graphql@16.9.0))(graphql@16.9.0)(react-dom@19.0.0(react@19.0.0))(react@19.0.0) + jsonwebtoken: + specifier: 'catalog:' + version: 9.0.2 + zod: + specifier: 'catalog:' + version: 3.24.1 devDependencies: '@graphql-codegen/cli': specifier: 'catalog:' @@ -349,9 +344,18 @@ importers: '@repo/typescript-config': specifier: workspace:* version: link:../typescript-config + '@types/jsonwebtoken': + specifier: 'catalog:' + version: 9.0.7 graphql: specifier: 'catalog:' version: 16.9.0 + vite-tsconfig-paths: + specifier: 'catalog:' + version: 5.1.4(typescript@5.7.2)(vite@5.4.11(@types/node@20.17.8)) + vitest: + specifier: 'catalog:' + version: 2.1.8(@types/node@20.17.8)(jsdom@25.0.1) packages/lint-staged-config: {}