-
Notifications
You must be signed in to change notification settings - Fork 3
WIP: Refactor db services and query building #218
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,8 @@ import type { BasicFractionWhereInput } from "./fractionInput.js"; | |
| import type { BasicMetadataWhereInput } from "./metadataInput.js"; | ||
| import type { BasicHypercertWhereArgs } from "./hypercertsInput.js"; | ||
| import type { BasicSignatureRequestWhereInput } from "./signatureRequestInput.js"; | ||
| import { BasicAttestationWhereInput } from "./attestationInput.js"; | ||
| import { BasicAttestationSchemaWhereInput } from "./attestationSchemaInput.js"; | ||
|
|
||
| export type WhereOptions<T extends object> = { | ||
| [P in keyof T]: | ||
|
|
@@ -25,5 +27,7 @@ export type WhereOptions<T extends object> = { | |
| | BasicContractWhereInput | ||
| | BasicFractionWhereInput | ||
| | BasicSignatureRequestWhereInput | ||
| | BasicAttestationWhereInput | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| | BasicAttestationSchemaWhereInput | ||
| | null; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,19 @@ | ||
| import { type ClassType, Field, Int, Resolver, ObjectType } from "type-graphql"; | ||
| import { SupabaseDataService } from "../../../services/SupabaseDataService.js"; | ||
| import { container } from "tsyringe"; | ||
| import { type ClassType, Field, Int, ObjectType, Resolver } from "type-graphql"; | ||
| import { SupabaseCachingService } from "../../../services/SupabaseCachingService.js"; | ||
| import { GetMetadataArgs } from "../args/metadataArgs.js"; | ||
| import { GetContractsArgs } from "../args/contractArgs.js"; | ||
| import { GetFractionsArgs } from "../args/fractionArgs.js"; | ||
| import { SupabaseDataService } from "../../../services/SupabaseDataService.js"; | ||
| import { GetAllowlistRecordsArgs } from "../args/allowlistRecordArgs.js"; | ||
| import { GetAttestationSchemasArgs } from "../args/attestationSchemaArgs.js"; | ||
| import { GetAttestationsArgs } from "../args/attestationArgs.js"; | ||
| import { GetAttestationSchemasArgs } from "../args/attestationSchemaArgs.js"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be cool to have an in this file? |
||
| import { GetBlueprintArgs } from "../args/blueprintArgs.js"; | ||
| import { GetContractsArgs } from "../args/contractArgs.js"; | ||
| import { GetFractionsArgs } from "../args/fractionArgs.js"; | ||
| import { GetHypercertsArgs } from "../args/hypercertsArgs.js"; | ||
| import { GetMetadataArgs } from "../args/metadataArgs.js"; | ||
| import { GetOrdersArgs } from "../args/orderArgs.js"; | ||
| import { GetSalesArgs } from "../args/salesArgs.js"; | ||
| import { GetUserArgs } from "../args/userArgs.js"; | ||
| import { GetBlueprintArgs } from "../args/blueprintArgs.js"; | ||
| import { GetSignatureRequestArgs } from "../args/signatureRequestArgs.js"; | ||
| import { GetUserArgs } from "../args/userArgs.js"; | ||
|
|
||
| export function DataResponse<TItem extends object>( | ||
| TItemClass: ClassType<TItem>, | ||
|
|
@@ -256,6 +257,7 @@ export function createBaseResolver<T extends ClassType>( | |
|
|
||
| try { | ||
| const queries = this.supabaseCachingService.getAttestations(args); | ||
|
|
||
| if (single) { | ||
| const res = await queries.data.executeTakeFirst(); | ||
| return res ? this.parseAttestation(res) : null; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| import { QueryStrategyFactory } from "./database/QueryBuilder.js"; | ||
|
|
||
| export abstract class BaseSupabaseService<DB> { | ||
| protected db: Kysely<DB>; | ||
| export abstract class BaseSupabaseService< | ||
| DB extends CachingDatabase | DataDatabase, | ||
| > { | ||
| protected constructor(protected db: Kysely<DB>) {} | ||
|
|
||
| protected constructor(db: Kysely<DB>) { | ||
| this.db = db; | ||
| } | ||
|
|
||
| abstract getDataQuery<T extends keyof DB & string, A extends object>( | ||
| tableName: T, | ||
| args: BaseArgs<A>, // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| ): any; | ||
|
|
||
| abstract getCountQuery<T extends keyof DB & string, A extends object>( | ||
| protected getDataQuery<T extends keyof DB>( | ||
| tableName: T, | ||
| args: BaseArgs<A>, // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| ): any; | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| args: BaseArgs<any>, | ||
| ) { | ||
| const strategy = QueryStrategyFactory.getStrategy<T, DB>(tableName); | ||
| return strategy.buildDataQuery(this.db, args); | ||
| } | ||
|
|
||
| handleGetData<T extends keyof DB & string, A extends object>( | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| protected getCountQuery<T extends keyof DB, A extends BaseArgs<any>>( | ||
| tableName: T, | ||
| args: BaseArgs<A> & { | ||
| first?: number; | ||
| offset?: number; | ||
| }, | ||
| args: A, | ||
| ) { | ||
| const strategy = QueryStrategyFactory.getStrategy<T, DB>(tableName); | ||
| return strategy.buildCountQuery(this.db, args); | ||
| } | ||
|
|
||
| protected handleGetData< | ||
| T extends keyof DB, | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| TRecord extends Record<string, any>, | ||
| >(tableName: T, args: BaseArgs<TRecord>) { | ||
| let query = this.getDataQuery(tableName, args); | ||
|
|
||
| const { where, first, offset, sort } = args; | ||
| const eb = expressionBuilder(query); | ||
|
|
||
|
|
@@ -45,13 +53,11 @@ export abstract class BaseSupabaseService<DB> { | |
| return query; | ||
| } | ||
|
|
||
| handleGetCount<T extends keyof DB & string, A extends object>( | ||
| tableName: T, | ||
| args: BaseArgs<A> & { | ||
| first?: number; | ||
| offset?: number; | ||
| }, | ||
| ) { | ||
| protected handleGetCount< | ||
| T extends keyof DB, | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| TRecord extends Record<string, any>, | ||
| >(tableName: T, args: BaseArgs<TRecord>) { | ||
| let query = this.getCountQuery(tableName, args); | ||
|
|
||
| const { where } = args; | ||
|
|
@@ -64,7 +70,8 @@ export abstract class BaseSupabaseService<DB> { | |
| return query; | ||
| } | ||
|
|
||
| private applyWhereConditions<T extends string>( | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| private applyWhereConditions<T extends keyof DB>( | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| query: any, | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
|
|
@@ -75,7 +82,7 @@ export abstract class BaseSupabaseService<DB> { | |
| ) { | ||
| const conditions = Object.entries(where) | ||
| .map(([column, value]) => | ||
| buildWhereCondition(column, value, tableName, eb), | ||
| buildWhereCondition(column, value, String(tableName), eb), | ||
| ) | ||
| .filter(Boolean); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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
Bcome from?