refactor: migrate CRM data layer from manual gqlFetch to Apollo Client

Replace custom gqlFetch() with proper Apollo useQuery/useMutation hooks
powered by codegen-generated TypedDocumentNode types. Key changes:

- Add GraphQL SDL schema file and codegen config for typescript-vue-apollo
- Replace all 28 raw .graphql imports with generated typed documents
- Add 12 useQuery() hooks with cache-and-network fetch policy
- Add 17 useMutation() hooks with surgical refetchQueries per mutation
- Optimistic cache update for setContactInboxHidden (instant archive UX)
- Fix contact list subtitle: show lastText instead of channel name
- Migrate login page from gqlFetch to useMutation
- WebSocket realtime now calls Apollo refetch instead of full data reload

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Ruslan Bakiev
2026-02-24 10:06:29 +07:00
parent 3e711a5533
commit 947ef4d56d
7 changed files with 2300 additions and 211 deletions

View File

@@ -1,16 +1,13 @@
import type { CodegenConfig } from "@graphql-codegen/cli";
const schemaUrl = process.env.GRAPHQL_SCHEMA_URL || process.env.GRAPHQL_HTTP_ENDPOINT || "http://localhost:3000/api/graphql";
const config: CodegenConfig = {
schema: schemaUrl,
schema: "graphql/schema.graphql",
documents: ["graphql/operations/**/*.graphql"],
generates: {
"composables/graphql/generated.ts": {
"graphql/generated.ts": {
plugins: [
"typescript",
"typescript-operations",
"typed-document-node",
"typescript-vue-apollo",
],
config: {
@@ -18,6 +15,7 @@ const config: CodegenConfig = {
vueCompositionApiImportFrom: "vue",
dedupeFragments: true,
namingConvention: "keep",
useTypeImports: true,
},
},
},