Skip to content

Refactor supabase services #263

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

Merged
merged 56 commits into from
Apr 17, 2025
Merged

Conversation

bitbeckers
Copy link
Collaborator

@bitbeckers bitbeckers commented Feb 13, 2025

The goal of the refactor is to improve the codebase for maintainability (easily adding functionality), testing (currently almost no gql tests), readability (simplifying the declaration all over the place) and code quality (any, any, any)

  • Refactor BaseSupabaseService to use strategies for querying tables
  • Introduce argGenerator method that allows for programmatically building the required where/sort arguments for an entity

TODO:

  • Simplify Resolvers
  • GraphQL code testing (including coverage)
  • Type checking

@bitbeckers bitbeckers added the enhancement New feature or request label Feb 13, 2025
@bitbeckers bitbeckers self-assigned this Feb 13, 2025
@bitbeckers bitbeckers force-pushed the feat/refactor_supabase_services branch 2 times, most recently from 0bf32e2 to 2daf033 Compare March 11, 2025 21:25
Copy link
Member

@pheuberger pheuberger left a comment

Choose a reason for hiding this comment

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

I'm exhausted

@pheuberger
Copy link
Member

pheuberger commented Mar 18, 2025

I just waded through a bunch of fix: ... and refactor: ... commits 🤠

When you are working on a feature, you make commits and subsequently you realize that the previous commits of your PR need some fixing, please fixup these commits directly instead of adding fix: ... commits to the PR.

This only makes it more difficult for people reviewing your code as they might lose time commenting on something that is already fixed in some later commit that they don't know is coming.

That's why I'd always suggest fixing your earlier commits directly, so that when somebody reviews that commit it is completely sound and final. There are of course exceptions to this rule; for example when you are working on a complicated refactor, but then there's a reason behind your commit strategy.

@pheuberger
Copy link
Member

Again, great work 🦾

Out of my review comments, there are only two things in my mind that should be cleaned up before merging this:

  1. Refactor supabase services #263 (comment)
  2. Refactor supabase services #263 (comment)

Everything else is not blocking.

Copy link

github-actions bot commented Apr 8, 2025

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 58.2% (🎯 58%) 110 / 189
🟢 Statements 58.2% (🎯 58%) 110 / 189
🟢 Functions 25.53% (🎯 25%) 12 / 47
🟢 Branches 38.98% (🎯 38%) 23 / 59
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/index.ts 0% 0% 0% 0% 1-2
src/client/graphql.ts 0% 0% 0% 0% 1-28
src/client/kysely.ts 100% 100% 100% 100%
src/commands/CommandFactory.ts 0% 0% 0% 0% 1
src/commands/MarketplaceCreateOrderCommand.ts 0% 0% 0% 0% 1
src/commands/SafeApiCommand.ts 0% 0% 0% 0% 1
src/commands/UserUpsertCommand.ts 0% 0% 0% 0% 1
src/controllers/AllowListController.ts 100% 100% 100% 100%
src/controllers/BlueprintController.ts 0% 0% 0% 0% 1
src/controllers/HyperboardController.ts 0% 0% 0% 0% 1
src/controllers/MarketplaceController.ts 0% 0% 0% 0% 1
src/controllers/MetadataController.ts 100% 100% 100% 100%
src/controllers/MonitoringController.ts 100% 100% 100% 100%
src/controllers/SignatureRequestController.ts 0% 0% 0% 0% 1
src/controllers/UploadController.ts 100% 100% 100% 100%
src/controllers/UserController.ts 0% 0% 0% 0% 1
src/lib/db/queryModifiers/applyPagination.ts 100% 100% 100% 100%
src/lib/db/queryModifiers/applySort.ts 100% 100% 100% 100%
src/lib/db/queryModifiers/applyWhere.ts 100% 100% 100% 100%
src/lib/db/queryModifiers/buildWhereCondition.ts 73.68% 88.88% 100% 73.68% 11-15
src/lib/db/queryModifiers/queryModifiers.ts 100% 100% 100% 100%
src/lib/db/queryModifiers/tableRelations.ts 100% 100% 100% 100%
src/lib/graphql/BaseQueryArgs.ts 100% 100% 100% 100%
src/lib/graphql/DataResponse.ts 100% 100% 100% 100%
src/lib/graphql/TypeRegistry.ts 100% 100% 100% 100%
src/lib/graphql/createEntityArgs.ts 100% 100% 100% 100%
src/lib/graphql/createEntitySortArgs.ts 100% 100% 100% 100%
src/lib/graphql/createEntityWhereArgs.ts 100% 100% 100% 100%
src/lib/graphql/whereFieldDefinitions.ts 100% 100% 100% 100%
src/lib/marketplace/EOACreateOrderStrategy.ts 0% 0% 0% 0% 1
src/lib/marketplace/MarketplaceStrategy.ts 0% 0% 0% 0% 1
src/lib/marketplace/MarketplaceStrategyFactory.ts 0% 0% 0% 0% 1
src/lib/marketplace/MultisigCreateOrderStrategy.ts 0% 0% 0% 0% 1
src/lib/strategies/isWhereEmpty.ts 100% 100% 100% 100%
src/lib/tsoa/iocContainer.ts 0% 0% 0% 0% 1
src/lib/users/EOAUpsertStrategy.ts 0% 0% 0% 0% 1
src/lib/users/MultisigUpsertStrategy.ts 0% 0% 0% 0% 1
src/lib/users/UserUpsertStrategy.ts 0% 0% 0% 0% 1
src/services/SignatureRequestProcessor.ts 0% 0% 0% 0% 1
src/services/database/entities/AllowListRecordEntityService.ts 100% 100% 100% 100%
src/services/database/entities/AttestationEntityService.ts 100% 100% 100% 100%
src/services/database/entities/AttestationSchemaEntityService.ts 100% 100% 100% 100%
src/services/database/entities/BlueprintsEntityService.ts 100% 100% 100% 100%
src/services/database/entities/CollectionEntityService.ts 100% 100% 100% 100%
src/services/database/entities/ContractEntityService.ts 100% 100% 100% 100%
src/services/database/entities/EntityServiceFactory.ts 100% 100% 100% 100%
src/services/database/entities/FractionEntityService.ts 100% 100% 100% 100%
src/services/database/entities/HyperboardEntityService.ts 100% 100% 100% 100%
src/services/database/entities/HypercertsEntityService.ts 100% 100% 100% 100%
src/services/database/entities/MarketplaceOrdersEntityService.ts 100% 100% 100% 100%
src/services/database/entities/MetadataEntityService.ts 100% 100% 100% 100%
src/services/database/entities/SalesEntityService.ts 100% 100% 100% 100%
src/services/database/entities/SignatureRequestsEntityService.ts 100% 100% 100% 100%
src/services/database/entities/UsersEntityService.ts 100% 100% 100% 100%
src/services/database/strategies/AllowlistQueryStrategy.ts 100% 100% 100% 100%
src/services/database/strategies/AttestationQueryStrategy.ts 100% 100% 100% 100%
src/services/database/strategies/BlueprintsQueryStrategy.ts 100% 100% 100% 100%
src/services/database/strategies/ClaimsQueryStrategy.ts 100% 100% 100% 100%
src/services/database/strategies/CollectionsQueryStrategy.ts 100% 100% 100% 100%
src/services/database/strategies/ContractsQueryStrategy.ts 100% 100% 100% 100%
src/services/database/strategies/FractionsQueryStrategy.ts 100% 100% 100% 100%
src/services/database/strategies/HyperboardsQueryStrategy.ts 100% 100% 100% 100%
src/services/database/strategies/MarketplaceOrdersQueryStrategy.ts 100% 100% 100% 100%
src/services/database/strategies/MetadataQueryStrategy.ts 100% 100% 100% 100%
src/services/database/strategies/QueryStrategy.ts 100% 100% 100% 100%
src/services/database/strategies/QueryStrategyFactory.ts 100% 100% 100% 100%
src/services/database/strategies/SalesQueryStrategy.ts 100% 100% 100% 100%
src/services/database/strategies/SignatureRequestsQueryStrategy.ts 100% 100% 100% 100%
src/services/database/strategies/SupportedSchemasQueryStrategy.ts 100% 100% 100% 100%
src/services/database/strategies/UsersQueryStrategy.ts 100% 100% 100% 100%
src/services/graphql/resolvers/allowlistRecordResolver.ts 100% 100% 100% 100%
src/services/graphql/resolvers/attestationResolver.ts 100% 100% 100% 100%
src/services/graphql/resolvers/attestationSchemaResolver.ts 100% 100% 100% 100%
src/services/graphql/resolvers/blueprintResolver.ts 100% 100% 100% 100%
src/services/graphql/resolvers/collectionResolver.ts 100% 100% 100% 100%
src/services/graphql/resolvers/contractResolver.ts 100% 100% 100% 100%
src/services/graphql/resolvers/fractionResolver.ts 100% 100% 100% 100%
src/services/graphql/resolvers/hyperboardResolver.ts 100% 100% 100% 100%
src/services/graphql/resolvers/hypercertResolver.ts 100% 100% 100% 100%
src/services/graphql/resolvers/metadataResolver.ts 100% 100% 100% 100%
src/services/graphql/resolvers/orderResolver.ts 100% 100% 100% 100%
src/services/graphql/resolvers/salesResolver.ts 100% 100% 100% 100%
src/services/graphql/resolvers/signatureRequestResolver.ts 100% 100% 100% 100%
src/services/graphql/resolvers/userResolver.ts 100% 100% 100% 100%
src/utils/addPriceInUSDToOrder.ts 100% 100% 100% 100%
src/utils/getCheapestOrder.ts 100% 100% 100% 100%
src/utils/getFractionsById.ts 0% 0% 0% 0% 1-12
src/utils/processCollectionToSection.ts 100% 100% 100% 100%
src/utils/processSectionsToHyperboardOwnership.ts 100% 100% 100% 100%
src/utils/validateMetadataAndClaimdata.ts 100% 100% 100% 100%
src/utils/waitForTxThenMintBlueprint.ts 0% 0% 0% 0% 1
Generated in workflow #98 for commit a4b32b8 by the Vitest Coverage Report Action

Refactors the base supabase service to apply strategies from
`QueryStrategies.ts` when queried. This simplifies the architecture of
the base service to have cleaner code and improve the testability and
typing of the codebase.

This is a setup for introducing more robust tests and removes the
abundance of any-typed fields
…rgument generation

Introduces a new `argGenerator.ts` to centralize and streamline GraphQL
argument generation across different entity types.

- Created a dynamic argument generation utility that reduces boilerplate
- Removed multiple (or all) input type files in favor of a more generic
approach
- Standardized argument generation for where, sort, and pagination
- Improved type safety and reduced code duplication
- Updated resolvers and type definitions to use the new argument
generation method
- basic tests for argGenerator method
The big one. This commit refactors all away the supabase services in
favor of services per entity.

Query strategies are generated for every tables query. When query args
are detected to referenced tables, the query building is applied
accordingly.

Creating a service for an entity defines the default getSingle and
getMany methods including the argumentation.

Field resolvers are implemented by using injected services and pass the
query args.

The created services also provide specific CRUD like methods, for
example getting collection admins by calling the collection_admins table
via the collections entity service.

The resolver classes are updated to use injected services for the base
type and fields resolvers where need.

As the services were also applied in the API flow, those are updates
following a similar approach.

This commit is the big refactor, subsequent commits add documentation
and test cases.
basic guide on how to add entities to the API
The createSortArgs, applySort and queryModifiers handled the sort fields
input differently.

This commit implements:
- sort fields can only be primitive type (i.e. not reference fields)
- sortBy is an optional fields
- undefined values in sort options
Refactored metadata-related files to use 'hypercerts' instead of 'claims' in query strategies and type definitions. Updated resolvers and type definitions to reflect the new relationship between metadata and hypercerts.
Refactored contract-related code to improve organization and maintainability:
- Moved ContractResolver from graphql to services directory
- Updated import paths in composed resolver
- Modified WhereFieldDefinitions for contract fields so that chain_id is bigint not number
- Enhanced ContractEntityService with comprehensive documentation
- Added detailed JSDoc comments for ContractService and ContractsQueryStrategy
- Updated field types and naming conventions for improved type safety
Refactored fraction-related code to improve organization and maintainability:
- Moved FractionResolver from graphql to services directory
- Updated import paths in composed resolver
- Relocated fractionResolver from local to services directory
- Enhanced FractionEntityService with comprehensive documentation
- Added detailed JSDoc comments for FractionService and FractionsQueryStrategy
- Introduced comprehensive test coverage for FractionService, FractionsQueryStrategy, and FractionResolver
- Improved type safety and code clarity across related files
- updated error handling to not throw in failed resolved fields queries
- introduced test utils for recurring methods
…returns

Implemented consistent error handling across multiple GraphQL resolvers:
- Updated AllowlistRecordResolver, AttestationResolver, AttestationSchemaResolver, ContractResolver, and FractionResolver
- Replaced error throwing with null returns for failed resolver queries
- Added detailed console error logging for debugging
- Updated corresponding test cases to expect null instead of thrown errors
- Improved resilience of GraphQL endpoint by preventing query failures
…lated services

Restructured metadata-related components to improve code organization:
- Removed MetadataResolver from graphql schemas
- Updated HypercertsEntityService to include metadata retrieval methods
- Modified MetadataQueryStrategy to simplify query generation
- Updated import paths in composed resolver and other resolvers
- Removed hypercert-specific filtering from metadata query strategy
- Relocated metadata-related methods to HypercertsService
- Updated test cases to reflect new metadata retrieval approach
…nents

Refactored hypercert-related code to improve organization and maintainability:
- Moved HypercertResolver from graphql to services directory
- Updated import paths in composed resolver
- Enhanced HypercertsEntityService with comprehensive documentation
- Added detailed JSDoc comments for HypercertService and ClaimsQueryStrategy
- Introduced comprehensive test coverage for HypercertsService, ClaimsQueryStrategy, and HypercertResolver
- Improved error handling to return null for failed resolver queries
- Updated schema to add new fields and improve type safety
Restructured sales-related components to improve code organization and maintainability:
- Moved SalesResolver from graphql to services directory
- Updated import paths in composed resolver
- Enhanced SalesEntityService with comprehensive documentation
- Added detailed JSDoc comments for SalesService and SalesQueryStrategy
- Introduced comprehensive test coverage for SalesService, SalesQueryStrategy, and SalesResolver
- Improved error handling to return null for failed resolver queries
- Standardized code structure with other similar resolvers
…nents

Refactored blueprint-related code to improve organization and maintainability:
- Moved BlueprintResolver from graphql to services directory
- Updated import paths in composed resolver
- Enhanced BlueprintsEntityService with comprehensive documentation
- Added detailed JSDoc comments for BlueprintsService and BlueprintResolver
- Introduced comprehensive test coverage for BlueprintsService, BlueprintResolver
- Updated Vitest configuration to adjust code coverage thresholds
- Improved error handling to return null for failed resolver queries
- Standardized code structure with other similar resolvers
- Introduced data database test utility for support the more complex interactions. For example the blueprint entityservice which interacts with multiple tables surin some method executions
…ponents

Restructured user-related code to improve organization and maintainability:
- Moved UserResolver from graphql to services directory
- Updated import paths in composed resolver
- Enhanced UsersEntityService with comprehensive documentation
- Added detailed JSDoc comments for UserService, UsersQueryStrategy, and UserResolver
- Introduced comprehensive test coverage for UsersService, UsersQueryStrategy, and UserResolver
- Improved error handling to return null for failed resolver queries
- Standardized code structure with other similar resolvers
- Added test utilities for generating mock user and signature request data
…ated services

Refactored collection-related components to improve organization and maintainability:
- moved CollectionResolver and updated import paths in composed resolver
- Enhanced CollectionService with comprehensive documentation and JSDoc comments
- Updated Vitest configuration to adjust code coverage thresholds
- Added new methods for managing collections, including CRUD operations and relationships
- Introduced test utilities for generating mock collection data
- Improved error handling and type safety across collection-related services
- Introduced test suite for resolver, entity service and query strategy
- Implements and polishes marketplace order entities handlers.
- Enhanced MarketplaceOrdersService with comprehensive documentation and new methods for order management
- Updated test coverage for OrderResolver and MarketplaceOrdersService, including error handling and mock data generation
- Introduced new utility functions for generating mock orders and collections
…lated components

- Introduced new fields in hyperboardArgs for collections and improved type definitions in hyperboardTypeDefs.
- Migrated HyperboardResolver to services directory
- Updated HyperboardService with comprehensive documentation and new methods for managing hyperboard collections and admins.
- Documented and tested HyperboardsQueryStrategy for optimized query handling with filtering capabilities.
- Added extensive test coverage for HyperboardResolver, HyperboardService, and HyperboardsQueryStrategy, ensuring robust functionality and error handling.
- Improved mock data generation utilities for hyperboards and related entities.
…nd enhance related components

- Moved signature request resolver and composed resolver to services dir
- Updaed SignatureRequestResolver with docs
- Enhanced SignatureRequestsService with detailed documentation and methods for managing signature requests.
- Added extensive test coverage for SignatureRequestsService and SignatureRequestResolver, ensuring robust functionality and error handling.
- Updated database schema to support signature requests and improved mock data generation utilities.
Makes the hyperboard owners and sections response type consistent with
other return types.
- Removed metadata image service, this has been split in the resolver
- Updated Order invalidation cron job to use injected marketplace order
service
- Refactored order invalidation cron job to be singleton usin tsyringe
- Updated tests
Add missing fields to order requests: created_at, invalidated and
invalidation codes
Copy link
Contributor

@Jipperism Jipperism left a comment

Choose a reason for hiding this comment

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

All my feedback has been addressed, so as far as I'm concerned this is good to go. I do notice the tests fail because the coverage targets are not hit, but I'll approve anyways for when those numbers get updated.

Copy link
Member

@pheuberger pheuberger left a comment

Choose a reason for hiding this comment

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

Closed 2-3 nits, so nothing blocking. LFG 🚂

bitbeckers and others added 3 commits April 17, 2025 16:03
coverage threshold
v2 monitoring
- Updated GraphQL endpoint references from v1 to v2 in README and development documentation.
- Adjusted API routes in various controllers to reflect the new v2 structure.
- Added new response types in schema.graphql for hyperboard and section entries.
- Updated test descriptions to align with the new v2 endpoints.
@bitbeckers bitbeckers merged commit e90a4c9 into develop Apr 17, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from In progress to Done in Hypercerts dev team daily ops Apr 17, 2025
@Jipperism Jipperism deleted the feat/refactor_supabase_services branch May 17, 2025 14:56
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: Done
Development

Successfully merging this pull request may close these issues.

3 participants