-
Notifications
You must be signed in to change notification settings - Fork 2
Create collections top level entity in GraphQL
#214
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
bitbeckers
merged 8 commits into
hypercerts-org:develop
from
pheuberger:create-collections-entity-graphql
Jan 28, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3f34a47
style: prettier format sorting.ts
pheuberger df469bb
fix: sort general supabase queries
pheuberger 8f847a6
chore: exclude services/ from coverage
pheuberger 39354f5
feat: add collections entity
pheuberger 2b15240
refactor: make env var assertion more intuitive
pheuberger 366915a
chore: remove unused import in instrument.mjs
pheuberger ccc0a57
test: simplify verifyAuthSignedData test
pheuberger cfeb432
test: mock RPC URL module in Safe sig verifier tests
pheuberger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { ArgsType, Field, InputType } from "type-graphql"; | ||
|
|
||
| import { BasicCollectionWhereInput } from "../inputs/collectionInput.js"; | ||
| import type { OrderOptions } from "../inputs/orderOptions.js"; | ||
| import { Collection } from "../typeDefs/collectionTypeDefs.js"; | ||
| import { CollectionSortOptions } from "../inputs/sortOptions.js"; | ||
|
|
||
| import { withPagination } from "./baseArgs.js"; | ||
|
|
||
| @InputType() | ||
| export class CollectionWhereInput extends BasicCollectionWhereInput {} | ||
|
|
||
| @InputType() | ||
| export class CollectionFetchInput implements OrderOptions<Collection> { | ||
| @Field(() => CollectionSortOptions, { nullable: true }) | ||
| by?: CollectionSortOptions; | ||
| } | ||
|
|
||
| @ArgsType() | ||
| export class CollectionArgs { | ||
| @Field(() => CollectionWhereInput, { nullable: true }) | ||
| where?: CollectionWhereInput; | ||
| @Field(() => CollectionFetchInput, { nullable: true }) | ||
| sort?: CollectionFetchInput; | ||
| } | ||
|
|
||
| @ArgsType() | ||
| export class GetCollectionsArgs extends withPagination(CollectionArgs) {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { Field, InputType } from "type-graphql"; | ||
|
|
||
| import { Collection } from "../typeDefs/collectionTypeDefs.js"; | ||
|
|
||
| import { IdSearchOptions, StringSearchOptions } from "./searchOptions.js"; | ||
| import type { WhereOptions } from "./whereOptions.js"; | ||
|
|
||
| @InputType() | ||
| export class BasicCollectionWhereInput implements WhereOptions<Collection> { | ||
| @Field(() => IdSearchOptions, { nullable: true }) | ||
| id?: IdSearchOptions | null; | ||
|
|
||
| @Field(() => StringSearchOptions, { nullable: true }) | ||
| name?: StringSearchOptions; | ||
|
|
||
| @Field(() => StringSearchOptions, { nullable: true }) | ||
| description?: StringSearchOptions; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| import { | ||
| Args, | ||
| FieldResolver, | ||
| ObjectType, | ||
| Query, | ||
| Resolver, | ||
| Root, | ||
| } from "type-graphql"; | ||
|
|
||
| import { GetCollectionsArgs } from "../args/collectionArgs.js"; | ||
| import { Collection } from "../typeDefs/collectionTypeDefs.js"; | ||
| import { Blueprint } from "../typeDefs/blueprintTypeDefs.js"; | ||
| import { User } from "../typeDefs/userTypeDefs.js"; | ||
|
|
||
| import { createBaseResolver, DataResponse } from "./baseTypes.js"; | ||
| import GetHypercertsResponse from "./hypercertResolver.js"; | ||
|
|
||
| @ObjectType() | ||
| class GetCollectionsResponse extends DataResponse(Collection) {} | ||
|
|
||
| const CollectionBaseResolver = createBaseResolver("collection"); | ||
|
|
||
| @Resolver(() => Collection) | ||
| class CollectionResolver extends CollectionBaseResolver { | ||
| @Query(() => GetCollectionsResponse) | ||
| async collections(@Args() args: GetCollectionsArgs) { | ||
| try { | ||
| const res = await this.supabaseDataService.getCollections(args); | ||
|
|
||
| return { | ||
| data: res.data, | ||
| count: res.count, | ||
| }; | ||
| } catch (e) { | ||
| console.error("[CollectionResolver::collections] Error:", e); | ||
| throw new Error(`Error fetching collections: ${(e as Error).message}`); | ||
| } | ||
| } | ||
|
|
||
| @FieldResolver(() => GetHypercertsResponse) | ||
| async hypercerts(@Root() collection: Collection) { | ||
| if (!collection.id) { | ||
| console.error( | ||
| "[CollectionResolver::hypercerts] Collection ID is undefined", | ||
| ); | ||
| return []; | ||
| } | ||
|
|
||
| const hypercerts = await this.supabaseDataService.getCollectionHypercerts( | ||
| collection.id, | ||
| ); | ||
|
|
||
| if (!hypercerts?.length) { | ||
| return []; | ||
| } | ||
|
|
||
| const hypercertIds = hypercerts | ||
| .map((h) => h.hypercert_id) | ||
| .filter((id): id is string => id !== undefined); | ||
|
|
||
| if (hypercertIds.length === 0) { | ||
| return []; | ||
| } | ||
|
|
||
| const hypercertsData = await this.getHypercerts({ | ||
| where: { hypercert_id: { in: hypercertIds } }, | ||
| }); | ||
|
|
||
| return hypercertsData.data || []; | ||
| } | ||
|
|
||
| @FieldResolver(() => [User]) | ||
| async admins(@Root() collection: Collection) { | ||
| if (!collection.id) { | ||
| console.error("[CollectionResolver::admins] Collection ID is undefined"); | ||
| return []; | ||
| } | ||
|
|
||
| const admins = await this.supabaseDataService.getCollectionAdmins( | ||
| collection.id, | ||
| ); | ||
| return admins || []; | ||
| } | ||
|
|
||
| @FieldResolver(() => [Blueprint]) | ||
| async blueprints(@Root() collection: Collection) { | ||
| if (!collection.id) { | ||
| console.error( | ||
| "[CollectionResolver::blueprints] Collection ID is undefined", | ||
| ); | ||
| return []; | ||
| } | ||
|
|
||
| const blueprints = await this.supabaseDataService.getCollectionBlueprints( | ||
| collection.id, | ||
| ); | ||
| return blueprints || []; | ||
| } | ||
| } | ||
|
|
||
| export { CollectionResolver }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { Field, ObjectType } from "type-graphql"; | ||
|
|
||
| import { EthBigInt } from "../../scalars/ethBigInt.js"; | ||
|
|
||
| import { BasicTypeDef } from "./baseTypes/basicTypeDef.js"; | ||
| import { User } from "./userTypeDefs.js"; | ||
| import { Hypercert } from "./hypercertTypeDefs.js"; | ||
| import { Blueprint } from "./blueprintTypeDefs.js"; | ||
|
|
||
| @ObjectType({ | ||
| description: "Collection of hypercerts for reference and display purposes", | ||
| }) | ||
| export class Collection extends BasicTypeDef { | ||
| @Field({ description: "Creation timestamp of the collection" }) | ||
| created_at?: string; | ||
| @Field({ description: "Name of the collection" }) | ||
| name?: string; | ||
| @Field({ description: "Description of the collection" }) | ||
| description?: string; | ||
| @Field(() => [EthBigInt], { | ||
| nullable: true, | ||
| description: "Chain ID of the collection", | ||
| }) | ||
| chain_ids?: (bigint | number | string)[]; | ||
|
|
||
| @Field(() => [User]) | ||
| admins?: User[]; | ||
|
|
||
| @Field(() => [Hypercert], { nullable: true }) | ||
| hypercerts?: Hypercert[]; | ||
|
|
||
| @Field(() => [Blueprint], { nullable: true }) | ||
| blueprints?: Blueprint[]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.