Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Refactor db services and query building #218

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

bitbeckers
Copy link
Collaborator

To improve the maintainability, readabiity and testability of the API codebase some major refactors were implemented.

The BaseSupabaseService is executes different strategies and applies where filtering and sorting.

Query Strategies and Factory were created for clear declaration of querying strategies

Tests were updated and basic tests for the services created. Including getting the graphql tests running with vitest

To improve the maintainability, readabiity and testability of the API
codebase some major refactors were implemented.

The BaseSupabaseService is executes different strategies and applies
where filtering and sorting.

Query Strategies and Factory were created for clear declaration of
querying strategies

Tests were updated and basic tests for the services created. Including
getting the graphql tests running with vitest
@bitbeckers bitbeckers added the enhancement New feature or request label Jan 22, 2025
@bitbeckers bitbeckers requested a review from pheuberger January 22, 2025 00:42
@bitbeckers bitbeckers self-assigned this Jan 22, 2025
Copy link

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 24.77% (🎯 17%) 27 / 109
🟢 Statements 24.77% (🎯 17%) 27 / 109
🔴 Functions 17.5% (🎯 54%) 7 / 40
🔴 Branches 17.5% (🎯 60%) 7 / 40
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/services/BaseSupabaseService.ts 100% 100% 100% 100%
src/services/SupabaseCachingService.ts 0% 0% 0% 0% 1
src/services/SupabaseDataService.ts 0% 0% 0% 0% 1-12
src/services/database/QueryBuilder.ts 100% 100% 100% 100%
src/services/database/QueryStrategies.ts 100% 100% 0% 100%
Generated in workflow #22 for commit 32e6fca by the Vitest Coverage Report Action

};

export function withPagination<TItem extends ClassType>(TItemClass: TItem) {
export function withPagination<TItem extends ClassType>(TItemClass: TItem): B {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused, where does B come from?

@@ -25,5 +27,7 @@ export type WhereOptions<T extends object> = {
| BasicContractWhereInput
| BasicFractionWhereInput
| BasicSignatureRequestWhereInput
| BasicAttestationWhereInput
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it difficult to know where in our code base we need to add which classes etc. Can we perhaps generate that somehow? If there was one file, that consolidated all the entities and their where-inputs and whatnot and we generate this type from there it would be a much better DX.

import { GetAttestationsArgs } from "../args/attestationArgs.js";
import { GetAttestationSchemasArgs } from "../args/attestationSchemaArgs.js";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be cool to have an /args/index.ts that exports all args and we do

import QueryArgs from "../args";

in this file?

@@ -2,32 +2,40 @@ import { expressionBuilder, Kysely, SqlBool } from "kysely";
import { BaseArgs } from "../graphql/schemas/args/baseArgs.js";
import { SortOrder } from "../graphql/schemas/enums/sortEnums.js";
import { buildWhereCondition } from "../graphql/schemas/utils/filters-kysely.js";
import { CachingDatabase } from "../types/kyselySupabaseCaching.js";
import { DataDatabase } from "../types/kyselySupabaseData.js";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be way out of scope for this PR, but generally, the names Caching Database and Data Database are a bit unwieldy and slightly confusing. Especially Data Database is making me twitch every time 😄 How about something like CoreData and ChainData? For me personally, Caching Database doesn't really tell me what I would find in there.

>(tableName: T): QueryStrategy<DB, T> {
const strategy = this.strategies[tableName as keyof StrategyMapping];
if (!strategy)
throw new Error(`No strategy found for table ${String(tableName)}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be cool to get a bit of a hint what to do when there's no strat found for the table.

@@ -0,0 +1,121 @@
import { Kysely } from "kysely";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder how useful these tests are. They're essentially just testing that the service is passing the args along.

pheuberger added a commit to pheuberger/hypercerts-api that referenced this pull request Jan 23, 2025
Our services are difficult to test at the moment and we don't really
have tests for them. However, when you make changes to the GraphQL
schema and potentially introduce new entities, you'll also alway have to
add code to the services and might go below the thresholds set.

PR hypercerts-org#218 is going to address this problem and make the services as well
as some of the GraphQL testable.

This is in anticipation of the next commit which is going to introduce
the collections entity as a top-level entity.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Ready
Development

Successfully merging this pull request may close these issues.

2 participants