b470cb21a1
## Summary This PR upgrades Apollo Client from v3.10.0 to v4 and refactors error handling patterns across the codebase to use a new centralized `useSnackBarOnQueryError` hook. ## Key Changes - **Dependency Update**: Upgraded `@apollo/client` from `^3.10.0` to `^3.11.0` in root package.json - **New Hook**: Added `useSnackBarOnQueryError` hook for centralized Apollo query error handling with snack bar notifications - **Error Handling Refactor**: Updated 100+ files to use the new error handling pattern: - Removed direct `ApolloError` imports where no longer needed - Replaced manual error handling logic with `useSnackBarOnQueryError` hook - Simplified error handling in hooks and components across multiple modules - **GraphQL Codegen**: Updated codegen configuration files to work with Apollo Client v3.11.0 - **Type Definitions**: Added TypeScript declaration file for `apollo-upload-client` module - **Test Updates**: Updated test files to reflect new error handling patterns ## Notable Implementation Details - The new `useSnackBarOnQueryError` hook provides a consistent way to handle Apollo query errors with automatic snack bar notifications - Changes span across multiple feature areas: auth, object records, settings, workflows, billing, and more - All changes maintain backward compatibility while improving code maintainability and reducing duplication - Jest configuration updated to work with the new Apollo Client version https://claude.ai/code/session_019WGZ6Rd7sEHuBg9sTrXRqJ --------- Co-authored-by: Claude <noreply@anthropic.com>
69 lines
1.7 KiB
TypeScript
69 lines
1.7 KiB
TypeScript
import { drizzle, type PostgresJsDatabase } from 'drizzle-orm/postgres-js';
|
|
import { migrate as postgresMigrate } from 'drizzle-orm/postgres-js/migrator';
|
|
import postgres from 'postgres';
|
|
import * as schema from './schema-postgres';
|
|
|
|
import 'dotenv/config';
|
|
|
|
let pgDb: PostgresJsDatabase<typeof schema>;
|
|
|
|
if (process.env.DATABASE_PG_URL) {
|
|
const pgClient = postgres(`${process.env.DATABASE_PG_URL}`);
|
|
pgDb = drizzle(pgClient, { schema, logger: false });
|
|
}
|
|
|
|
const migrate = async () => {
|
|
await postgresMigrate(pgDb, {
|
|
migrationsFolder: './src/database/migrations',
|
|
});
|
|
};
|
|
|
|
const findOne = (model: any, orderBy: any) => {
|
|
return pgDb.select().from(model).orderBy(orderBy).limit(1).execute();
|
|
};
|
|
|
|
const findAll = (model: any, orderBy?: any) => {
|
|
if (orderBy) {
|
|
return pgDb.select().from(model).orderBy(orderBy).execute();
|
|
}
|
|
return pgDb.select().from(model).execute();
|
|
};
|
|
|
|
const insertMany = async (
|
|
model: any,
|
|
data: any,
|
|
options?: {
|
|
onConflictKey?: string;
|
|
onConflictUpdateObject?: any;
|
|
onConflictDoNothing?: boolean;
|
|
},
|
|
) => {
|
|
const query = pgDb.insert(model).values(data);
|
|
|
|
if (options?.onConflictUpdateObject) {
|
|
if (options?.onConflictKey) {
|
|
return query
|
|
.onConflictDoUpdate({
|
|
target: [model[options.onConflictKey]],
|
|
set: options.onConflictUpdateObject,
|
|
})
|
|
.execute();
|
|
}
|
|
}
|
|
|
|
if (options?.onConflictDoNothing && !options?.onConflictKey) {
|
|
return query.onConflictDoNothing().execute();
|
|
}
|
|
|
|
if (options?.onConflictKey) {
|
|
return query
|
|
.onConflictDoNothing({
|
|
target: [model[options.onConflictKey]],
|
|
})
|
|
.execute();
|
|
}
|
|
return query.execute();
|
|
};
|
|
|
|
export { findAll, findOne, insertMany, migrate };
|