Use 2 replicas of GraphQL API and make slonik interceptor type-safe (#360)

* type-safe slonik interceptor

* Use 2 replicas of graphql-api
This commit is contained in:
Kamil Kisiela 2022-09-14 09:52:04 +02:00 committed by GitHub
parent bce8aa2c16
commit 80d971f24d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 7 deletions

View file

@ -1,3 +1,8 @@
{
"recommendations": ["fabiospampinato.vscode-terminals", "fabiospampinato.vscode-commands", "esbenp.prettier-vscode"]
"recommendations": [
"fabiospampinato.vscode-terminals",
"fabiospampinato.vscode-commands",
"esbenp.prettier-vscode",
"thebearingedge.vscode-sql-lit"
]
}

View file

@ -74,7 +74,7 @@ export function deployGraphQL({
'graphql-api',
{
storageContainer,
replicas: 1,
replicas: 2,
readinessProbe: '/_readiness',
livenessProbe: '/_health',
env: {

View file

@ -1,9 +1,15 @@
/// <reference path="../module.d.ts" />
import { createPool, TaggedTemplateLiteralInvocation, QueryResultRowColumn, CommonQueryMethods } from 'slonik';
import {
createPool,
TaggedTemplateLiteralInvocation,
QueryResultRowColumn,
CommonQueryMethods,
Interceptor,
QueryResultRow,
} from 'slonik';
import { createQueryLoggingInterceptor } from 'slonik-interceptor-query-logging';
import { createSentryInterceptor } from './sentry';
const dbInterceptors = [createQueryLoggingInterceptor(), createSentryInterceptor()];
const dbInterceptors: Interceptor[] = [createQueryLoggingInterceptor(), createSentryInterceptor()];
export async function getPool(connection: string) {
const pool = await createPool(connection, {
@ -14,7 +20,11 @@ export async function getPool(connection: string) {
function interceptError<K extends Exclude<keyof CommonQueryMethods, 'transaction'>>(methodName: K) {
const original: CommonQueryMethods[K] = pool[methodName];
function interceptor<T>(this: any, sql: TaggedTemplateLiteralInvocation<T>, values?: QueryResultRowColumn[]): any {
function interceptor<T extends QueryResultRow>(
this: any,
sql: TaggedTemplateLiteralInvocation<T>,
values?: QueryResultRowColumn[]
): any {
return (original as any).call(this, sql, values).catch((error: any) => {
error.sql = sql.sql;
error.values = sql.values || values;

View file

@ -1 +0,0 @@
declare module 'slonik-interceptor-query-logging';