From 361ce7955ccda8ef147f0bd3b5b79759db8eb809 Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Tue, 21 Feb 2023 10:06:42 -0800 Subject: [PATCH 01/16] feat: Add POST in CORS methods --- src/server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server.ts b/src/server.ts index 0a9207f..58d142a 100644 --- a/src/server.ts +++ b/src/server.ts @@ -36,7 +36,7 @@ export function buildServer(context: GraphQLContext) { plugins, cors: { origin: process.env.CORS_ORIGIN ?? '*', - methods: ['GET'], + methods: ['GET', 'POST'], }, context, }); From ab5de5146017fe6b9197967b93b7bbc12902db20 Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Tue, 21 Feb 2023 10:11:31 -0800 Subject: [PATCH 02/16] feat: Add better error message for missing PGCONN env var --- src/db/archive-node-adapter/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/db/archive-node-adapter/index.ts b/src/db/archive-node-adapter/index.ts index 7ee6709..ca3e1da 100644 --- a/src/db/archive-node-adapter/index.ts +++ b/src/db/archive-node-adapter/index.ts @@ -22,7 +22,10 @@ export class ArchiveNodeAdapter implements DatabaseAdapter { private client: postgres.Sql; constructor(connectionString: string | undefined) { - if (!connectionString) throw new Error('Missing connection string'); + if (!connectionString) + throw new Error( + 'Missing Postgres Connection String. Please provide a valid connection string in the environment variables or in your configuration file to connect to the Postgres database.' + ); this.client = postgres(connectionString); } From c1d32fa8a2c32269fecafe1025de57c07e529f46 Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Tue, 21 Feb 2023 11:55:44 -0800 Subject: [PATCH 03/16] feat: Check if SQL schema is compatible --- src/context.ts | 6 ++++-- src/db/archive-node-adapter/index.ts | 21 ++++++++++++++++++++- src/db/archive-node-adapter/queries.ts | 19 +++++++++++++++++++ src/index.ts | 8 +++----- 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/src/context.ts b/src/context.ts index 04be3d5..f1402de 100644 --- a/src/context.ts +++ b/src/context.ts @@ -4,8 +4,10 @@ export interface GraphQLContext { db_client: DatabaseAdapter; } -export function buildContext(connectionString: string | undefined) { +export async function buildContext(connectionString: string | undefined) { + const db_client = new ArchiveNodeAdapter(connectionString); + await db_client.checkSQLSchema(); return { - db_client: new ArchiveNodeAdapter(connectionString), + db_client, }; } diff --git a/src/db/archive-node-adapter/index.ts b/src/db/archive-node-adapter/index.ts index ca3e1da..df01e89 100644 --- a/src/db/archive-node-adapter/index.ts +++ b/src/db/archive-node-adapter/index.ts @@ -13,7 +13,12 @@ import { createEvent, createAction, } from '../../models/utils'; -import { getActionsQuery, getEventsQuery } from './queries'; +import { + getActionsQuery, + getEventsQuery, + getTables, + USED_TABLES, +} from './queries'; import type { DatabaseAdapter } from '../index'; import type { EventFilterOptionsInput } from '../../resolvers-types'; @@ -29,6 +34,20 @@ export class ArchiveNodeAdapter implements DatabaseAdapter { this.client = postgres(connectionString); } + async checkSQLSchema() { + let tables = await ( + await getTables(this.client) + ).map((table) => table.tablename); + + for (let table of USED_TABLES) { + if (!tables.includes(table)) { + throw new Error( + `Missing table ${table}. Please make sure the table exists in the database.` + ); + } + } + } + async close() { return this.client.end(); } diff --git a/src/db/archive-node-adapter/queries.ts b/src/db/archive-node-adapter/queries.ts index bf8dcce..83d5194 100644 --- a/src/db/archive-node-adapter/queries.ts +++ b/src/db/archive-node-adapter/queries.ts @@ -160,3 +160,22 @@ export function getActionsQuery( ORDER BY timestamp DESC, state_hash DESC `; } + +export function getTables(db_client: postgres.Sql) { + return db_client` + SELECT tablename FROM pg_catalog.pg_tables where schemaname='public'; + `; +} + +export const USED_TABLES = [ + 'blocks', + 'account_identifiers', + 'accounts_accessed', + 'blocks_zkapp_commands', + 'zkapp_commands', + 'zkapp_account_update', + 'zkapp_account_update_body', + 'zkapp_events', + 'zkapp_state_data_array', + 'zkapp_state_data', +] as const; diff --git a/src/index.ts b/src/index.ts index 78ff4b1..62c98e4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,8 +6,8 @@ import { buildServer } from './server'; const PORT = process.env.PORT || 8080; -function main() { - const context = buildContext(process.env.PG_CONN); +(async function main() { + const context = await buildContext(process.env.PG_CONN); const server = buildServer(context); ['SIGINT', 'SIGTERM', 'SIGQUIT'].forEach((signal) => { @@ -21,6 +21,4 @@ function main() { server.listen(PORT, () => { console.info(`Server is running on port: ${PORT}`); }); -} - -main(); +})(); From 5755108f553e86ffd80d39f900971bcf0d5a5eca Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Tue, 21 Feb 2023 11:56:03 -0800 Subject: [PATCH 04/16] refactor: Change defaultTokenId name --- src/db/archive-node-adapter/index.ts | 10 +++++----- src/models/types.ts | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/db/archive-node-adapter/index.ts b/src/db/archive-node-adapter/index.ts index df01e89..074b17e 100644 --- a/src/db/archive-node-adapter/index.ts +++ b/src/db/archive-node-adapter/index.ts @@ -3,7 +3,7 @@ import { Action, Actions, BlockStatusFilter, - defaultTokenID, + DEFAULT_TOKEN_ID, Event, Events, } from '../../models/types'; @@ -35,11 +35,11 @@ export class ArchiveNodeAdapter implements DatabaseAdapter { } async checkSQLSchema() { - let tables = await ( + const tables = await ( await getTables(this.client) ).map((table) => table.tablename); - for (let table of USED_TABLES) { + for (const table of USED_TABLES) { if (!tables.includes(table)) { throw new Error( `Missing table ${table}. Please make sure the table exists in the database.` @@ -82,7 +82,7 @@ export class ArchiveNodeAdapter implements DatabaseAdapter { const { address, to, from } = input; let { tokenId, status } = input; - tokenId ||= defaultTokenID; + tokenId ||= DEFAULT_TOKEN_ID; status ||= BlockStatusFilter.all; if (to && from && to < from) { throw new Error('to must be greater than from'); @@ -102,7 +102,7 @@ export class ArchiveNodeAdapter implements DatabaseAdapter { const { address, to, from } = input; let { tokenId, status } = input; - tokenId ||= defaultTokenID; + tokenId ||= DEFAULT_TOKEN_ID; status ||= BlockStatusFilter.all; if (to && from && to < from) { throw new Error('to must be greater than from'); diff --git a/src/models/types.ts b/src/models/types.ts index 6587c66..6289ea1 100644 --- a/src/models/types.ts +++ b/src/models/types.ts @@ -1,5 +1,5 @@ -export const defaultTokenID = - 'wSHV2S4qX9jFsLjQo8r1BsMLH2ZRKsZx6EJd1sbozGPieEC4Jf'; +export const DEFAULT_TOKEN_ID = + 'wSHV2S4qX9jFsLjQo8r1BsMLH2ZRKsZx6EJd1sbozGPieEC4Jf' as const; export enum BlockStatusFilter { all = 'ALL', From 719c76ca34a60f105f0c9df7aa4f9a07f6e46819 Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Tue, 21 Feb 2023 11:56:14 -0800 Subject: [PATCH 05/16] chore: Minor refactors --- package.json | 1 + src/models/utils.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 87f1a5f..07dcecf 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "url": "https://github.com/o1-labs/Archive-Node-API" }, "main": "build/src/index.js", + "start": "build/src/index.js", "scripts": { "build": "tsc", "start": "node build/src/index.js", diff --git a/src/models/utils.ts b/src/models/utils.ts index ad08218..735b1d9 100644 --- a/src/models/utils.ts +++ b/src/models/utils.ts @@ -1,5 +1,5 @@ -import type { BlockInfo, TransactionInfo, Event, Action } from './types'; import type postgres from 'postgres'; +import type { BlockInfo, TransactionInfo, Event, Action } from './types'; export function createBlockInfo(row: postgres.Row) { return { From 8d2d14aa9d0bfe0a2c3d64c9149af82cb3c06c0c Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Tue, 21 Feb 2023 12:04:32 -0800 Subject: [PATCH 06/16] feat: Add error checking for logging env vars --- src/envionment.d.ts | 1 + src/server.ts | 41 +++++++++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/envionment.d.ts b/src/envionment.d.ts index 38ac4f6..d7ed884 100644 --- a/src/envionment.d.ts +++ b/src/envionment.d.ts @@ -4,6 +4,7 @@ declare global { PORT?: string; PG_CONN: string; CORS_ORIGIN?: string; + ENABLE_LOGGING?: bool; ENABLE_INTROSPECTION?: bool; ENABLE_GRAPHIQL?: bool; ENABLE_JAEGER?: bool; diff --git a/src/server.ts b/src/server.ts index 58d142a..8639490 100644 --- a/src/server.ts +++ b/src/server.ts @@ -10,19 +10,40 @@ import type { GraphQLContext } from './context'; const LOG_LEVEL = (process.env.LOG_LEVEL as LogLevel) || 'info'; +function initJaegerProvider() { + let provider = undefined; + if (process.env.ENABLE_JAEGER) { + provider = buildProvider(); + if (!process.env.JAEGER_ENDPOINT) { + throw new Error( + 'Jaeger endpoint not found. Please ensure that the Jaeger endpoint is properly configured and available.' + ); + } + if (!process.env.JAEGER_SERVICE_NAME) { + throw new Error( + 'Jaeger service name not found. Please ensure that the Jaeger service name is properly configured and available.' + ); + } + } + return provider; +} + export function buildServer(context: GraphQLContext) { const plugins = []; plugins.push(useGraphQlJit()); - plugins.push( - useOpenTelemetry( - { - resolvers: false, // Tracks resolvers calls, and tracks resolvers thrown errors - variables: true, // Includes the operation variables values as part of the metadata collected - result: true, // Includes execution result object as part of the metadata collected - }, - process.env.ENABLE_JAEGER ? buildProvider() : undefined - ) - ); + if (process.env.ENABLE_LOGGING === 'true') { + let provider = initJaegerProvider(); + plugins.push( + useOpenTelemetry( + { + resolvers: false, // Tracks resolvers calls, and tracks resolvers thrown errors + variables: true, // Includes the operation variables values as part of the metadata collected + result: true, // Includes execution result object as part of the metadata collected + }, + provider + ) + ); + } if (process.env.ENABLE_INTROSPECTION !== 'true') plugins.push(useDisableIntrospection()); From 4ff34198bd16d7b37ca3d95d41730b292308036b Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Tue, 21 Feb 2023 12:05:54 -0800 Subject: [PATCH 07/16] chore: Add ENABLE_LOGGING to env.example --- .env.example | 1 + 1 file changed, 1 insertion(+) diff --git a/.env.example b/.env.example index 9f41f63..a88b139 100644 --- a/.env.example +++ b/.env.example @@ -6,6 +6,7 @@ PG_CONN="postgres://postgres:password@localhost:5432/archive" ENABLE_GRAPHIQL="true" ENABLE_INTROSPECTION="true" +ENABLE_LOGGING="true" ENABLE_JAEGER="true" JAEGER_SERVICE_NAME="archive-api" JAEGER_ENDPOINT='http://localhost:14268/api/traces' From e42eef9b6668deb0d8e646567920ff2d8223d33f Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Tue, 21 Feb 2023 12:07:43 -0800 Subject: [PATCH 08/16] refactor: Add buildPlugins function --- src/server.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/server.ts b/src/server.ts index 8639490..e3a1496 100644 --- a/src/server.ts +++ b/src/server.ts @@ -28,11 +28,13 @@ function initJaegerProvider() { return provider; } -export function buildServer(context: GraphQLContext) { +function buildPlugins() { const plugins = []; + plugins.push(useGraphQlJit()); + if (process.env.ENABLE_LOGGING === 'true') { - let provider = initJaegerProvider(); + const provider = initJaegerProvider(); plugins.push( useOpenTelemetry( { @@ -44,9 +46,14 @@ export function buildServer(context: GraphQLContext) { ) ); } - if (process.env.ENABLE_INTROSPECTION !== 'true') + + if (!process.env.ENABLE_INTROSPECTION) plugins.push(useDisableIntrospection()); + return plugins; +} + +export function buildServer(context: GraphQLContext) { const yoga = createYoga({ schema, logging: LOG_LEVEL, @@ -54,7 +61,7 @@ export function buildServer(context: GraphQLContext) { landingPage: false, healthCheckEndpoint: '/healthcheck', graphiql: process.env.ENABLE_GRAPHIQL === 'true' ? true : false, - plugins, + plugins: buildPlugins(), cors: { origin: process.env.CORS_ORIGIN ?? '*', methods: ['GET', 'POST'], From b2686e467df4a110816c797280186df971450a90 Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Tue, 21 Feb 2023 13:04:52 -0800 Subject: [PATCH 09/16] chore: Remove unnecessary assignment in resolvers --- src/resolvers.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/resolvers.ts b/src/resolvers.ts index 208bcae..3c5b61b 100644 --- a/src/resolvers.ts +++ b/src/resolvers.ts @@ -5,12 +5,10 @@ import { Resolvers } from './resolvers-types'; export const resolvers: Resolvers = { Query: { events: async (_, { input }, { db_client }) => { - const fetchedEvents = await db_client.getEvents(input); - return fetchedEvents; + return db_client.getEvents(input); }, actions: async (_, { input }, { db_client }) => { - const fetchedActions = await db_client.getActions(input); - return fetchedActions; + return db_client.getActions(input); }, }, }; From cdc8b2981460e6665bf62570dc76c9202c15f539 Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Wed, 22 Feb 2023 09:24:26 -0800 Subject: [PATCH 10/16] feat: Add connectivity check to Jaeger endpoint --- src/server.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/server.ts b/src/server.ts index e3a1496..f185526 100644 --- a/src/server.ts +++ b/src/server.ts @@ -3,6 +3,7 @@ import { createServer } from 'http'; import { useGraphQlJit } from '@envelop/graphql-jit'; import { useDisableIntrospection } from '@envelop/disable-introspection'; import { useOpenTelemetry } from '@envelop/opentelemetry'; +import http from 'node:http'; import { buildProvider } from './tracing'; import { schema } from './resolvers'; @@ -24,6 +25,26 @@ function initJaegerProvider() { 'Jaeger service name not found. Please ensure that the Jaeger service name is properly configured and available.' ); } + + // Check if Jaeger endpoint is available. + let [hostname, port] = process.env.JAEGER_ENDPOINT.replace( + 'http://', + '' + ).split(':'); + port = port?.split('/')[0]; + const req = http.request({ + hostname, + method: 'GET', + port, + path: '/', + }); + req.on('error', () => { + throw new Error( + 'Jaeger endpoint not available. Please ensure that the Jaeger endpoint is properly configured and available.' + ); + }); + req.end(); + req.socket?.end?.(); } return provider; } From 0a26570e1d37d5c0da3b5c49b5a06e3ed88c38af Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Wed, 22 Feb 2023 10:55:51 -0800 Subject: [PATCH 11/16] feat: Add error logging to console --- .env.example | 1 + src/envionment.d.ts | 1 + src/server.ts | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/.env.example b/.env.example index a88b139..6b4435e 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,5 @@ PORT=8080 +LOG_LEVEL="debug" CORS_ORIGIN="*" PG_CONN="postgres://postgres:password@localhost:5432/archive" diff --git a/src/envionment.d.ts b/src/envionment.d.ts index d7ed884..95cf7a6 100644 --- a/src/envionment.d.ts +++ b/src/envionment.d.ts @@ -1,6 +1,7 @@ declare global { namespace NodeJS { interface ProcessEnv { + LOG_LEVEL: string; PORT?: string; PG_CONN: string; CORS_ORIGIN?: string; diff --git a/src/server.ts b/src/server.ts index f185526..2d6672f 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,5 +1,6 @@ import { createYoga, LogLevel } from 'graphql-yoga'; import { createServer } from 'http'; +import { useLogger } from '@envelop/core'; import { useGraphQlJit } from '@envelop/graphql-jit'; import { useDisableIntrospection } from '@envelop/disable-introspection'; import { useOpenTelemetry } from '@envelop/opentelemetry'; @@ -71,6 +72,27 @@ function buildPlugins() { if (!process.env.ENABLE_INTROSPECTION) plugins.push(useDisableIntrospection()); + plugins.push( + useLogger({ + logFn: (eventName, args) => { + if (args?.result?.errors) { + console.debug( + eventName, + inspect(args.args.contextValue.params, { + showHidden: false, + depth: null, + colors: true, + }), + inspect(args.result.errors, { + showHidden: false, + depth: null, + colors: true, + }) + ); + } + }, + }) + ); return plugins; } From 752f3660c8b69c2a16d9cd43ef38565d10dbb721 Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Wed, 22 Feb 2023 10:56:20 -0800 Subject: [PATCH 12/16] refactor: Slight refactor for Jaeger endpoint connectivity --- src/server.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/server.ts b/src/server.ts index 2d6672f..b435479 100644 --- a/src/server.ts +++ b/src/server.ts @@ -4,7 +4,9 @@ import { useLogger } from '@envelop/core'; import { useGraphQlJit } from '@envelop/graphql-jit'; import { useDisableIntrospection } from '@envelop/disable-introspection'; import { useOpenTelemetry } from '@envelop/opentelemetry'; -import http from 'node:http'; + +import { request } from 'node:http'; +import { inspect } from 'node:util'; import { buildProvider } from './tracing'; import { schema } from './resolvers'; @@ -33,7 +35,7 @@ function initJaegerProvider() { '' ).split(':'); port = port?.split('/')[0]; - const req = http.request({ + const req = request({ hostname, method: 'GET', port, From a1b61eeebdfde05adf1bb247b0aca3aabe0b90c7 Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Wed, 22 Feb 2023 14:51:35 -0800 Subject: [PATCH 13/16] feat: Add better error message when trying to connect to DB --- src/context.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/context.ts b/src/context.ts index f1402de..cfaf981 100644 --- a/src/context.ts +++ b/src/context.ts @@ -6,7 +6,13 @@ export interface GraphQLContext { export async function buildContext(connectionString: string | undefined) { const db_client = new ArchiveNodeAdapter(connectionString); - await db_client.checkSQLSchema(); + try { + await db_client.checkSQLSchema(); + } catch (e) { + throw new Error( + `Could not connect to Postgres with the specified connection string. Please check that Postgres is available and that your connection string is correct and try again.\nReason: ${e}` + ); + } return { db_client, }; From 5616fa2a4ab9a09db923545757d5a1e00edb5e60 Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Fri, 24 Feb 2023 10:17:51 -0800 Subject: [PATCH 14/16] feat: fix logging conditional --- .env.example | 2 +- src/server.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 6b4435e..b8f0313 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ PORT=8080 -LOG_LEVEL="debug" +LOG_LEVEL="info" CORS_ORIGIN="*" PG_CONN="postgres://postgres:password@localhost:5432/archive" diff --git a/src/server.ts b/src/server.ts index b435479..75d5d42 100644 --- a/src/server.ts +++ b/src/server.ts @@ -30,6 +30,7 @@ function initJaegerProvider() { } // Check if Jaeger endpoint is available. + // eslint-disable-next-line prefer-const let [hostname, port] = process.env.JAEGER_ENDPOINT.replace( 'http://', '' @@ -56,8 +57,7 @@ function buildPlugins() { const plugins = []; plugins.push(useGraphQlJit()); - - if (process.env.ENABLE_LOGGING === 'true') { + if (process.env.ENABLE_LOGGING) { const provider = initJaegerProvider(); plugins.push( useOpenTelemetry( From 21e36a823b9aced110c3d9b9e7459ccf215f0231 Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Fri, 24 Feb 2023 10:45:35 -0800 Subject: [PATCH 15/16] feat: Add timeout for Jaeger and better error messages --- src/index.ts | 5 +++-- src/server.ts | 19 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index 62c98e4..7fbfa61 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,8 +14,9 @@ const PORT = process.env.PORT || 8080; process.on(signal, () => server.close()); }); - server.on('close', () => { - context.db_client.close(); + server.on('close', async () => { + await context.db_client.close(); + process.exit(1); }); server.listen(PORT, () => { diff --git a/src/server.ts b/src/server.ts index 75d5d42..3ef4870 100644 --- a/src/server.ts +++ b/src/server.ts @@ -20,33 +20,37 @@ function initJaegerProvider() { provider = buildProvider(); if (!process.env.JAEGER_ENDPOINT) { throw new Error( - 'Jaeger endpoint not found. Please ensure that the Jaeger endpoint is properly configured and available.' + 'Jaeger was enabled but no endpoint was specified. Please ensure that the Jaeger endpoint is properly configured and available.' ); } if (!process.env.JAEGER_SERVICE_NAME) { throw new Error( - 'Jaeger service name not found. Please ensure that the Jaeger service name is properly configured and available.' + 'Jaeger was enabled but no service name was specified. Please ensure that the Jaeger service name is properly configured.' ); } // Check if Jaeger endpoint is available. + const endpoint = process.env.JAEGER_ENDPOINT.replace(/(^\w+:|^)\/\//, ''); // eslint-disable-next-line prefer-const - let [hostname, port] = process.env.JAEGER_ENDPOINT.replace( - 'http://', - '' - ).split(':'); + let [hostname, port] = endpoint.split(':'); port = port?.split('/')[0]; const req = request({ hostname, method: 'GET', port, path: '/', + timeout: 2000, }); req.on('error', () => { throw new Error( 'Jaeger endpoint not available. Please ensure that the Jaeger endpoint is properly configured and available.' ); }); + req.on('timeout', () => { + throw new Error( + 'Jaeger endpoint timed out. Please ensure that the Jaeger endpoint is properly configured and available.' + ); + }); req.end(); req.socket?.end?.(); } @@ -99,6 +103,7 @@ function buildPlugins() { } export function buildServer(context: GraphQLContext) { + const plugins = buildPlugins(); const yoga = createYoga({ schema, logging: LOG_LEVEL, @@ -106,7 +111,7 @@ export function buildServer(context: GraphQLContext) { landingPage: false, healthCheckEndpoint: '/healthcheck', graphiql: process.env.ENABLE_GRAPHIQL === 'true' ? true : false, - plugins: buildPlugins(), + plugins, cors: { origin: process.env.CORS_ORIGIN ?? '*', methods: ['GET', 'POST'], From 710682295ca87de81b58f1a2cfb8b31a8370df00 Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Fri, 24 Feb 2023 10:51:18 -0800 Subject: [PATCH 16/16] feat: Slight test refactor --- tests/archive-node-adapter.test.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/archive-node-adapter.test.ts b/tests/archive-node-adapter.test.ts index fc2d079..db5a0ba 100644 --- a/tests/archive-node-adapter.test.ts +++ b/tests/archive-node-adapter.test.ts @@ -1,4 +1,4 @@ -import { expect, test, describe } from 'vitest'; +import { expect, test, describe, beforeAll } from 'vitest'; import postgres from 'postgres'; import database_mock from './mocked_sql/database_mock.json'; @@ -47,9 +47,13 @@ class ArchiveNodeAdapterExtend extends ArchiveNodeAdapter { } } -const archiveNodeAdapter = new ArchiveNodeAdapterExtend(PG_CONN); +let archiveNodeAdapter; describe('ArchiveNodeAdapter', async () => { + beforeAll(() => { + archiveNodeAdapter = new ArchiveNodeAdapterExtend(PG_CONN); + }); + describe('partitionBlocks', async () => { test('partitionBlocks should return a non-empty map', async () => { const blocksMap = archiveNodeAdapter.partitionBlocksExtended(