-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Without this patch the user of our GraphQL endpoints needs to go via hyperboards to access the collections inside. Another drawback is that via this query they can only access the hypercert id, so they'll have to fire a separate query to combine the data. This patch adds collections as a top level entity and exposes full hypercert objects as child entities. This also applies to hyperboards as the standalone collections entity is being reused there too.
- Loading branch information
1 parent
05b1e8d
commit 268f190
Showing
9 changed files
with
301 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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.