-
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.
(feat): add support for collection entity in graphql api (#84)
* (feat): add support for collection entity in graphql api * (chore): update logging * (fix): update naming and chain id type
- Loading branch information
Showing
9 changed files
with
395 additions
and
0 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,17 @@ | ||
import { ArgsType, Field } from "type-graphql"; | ||
import { PaginationArgs } from "./paginationArgs.js"; | ||
import {BasicCollectionWhereInput, CollectionFetchInput} from "../inputs/collectionInput.js"; | ||
|
||
@ArgsType() | ||
export class GetCollectionArgs extends PaginationArgs { | ||
@Field({ nullable: true }) | ||
where?: BasicCollectionWhereInput; | ||
@Field({ nullable: true }) | ||
sort?: CollectionFetchInput; | ||
} | ||
|
||
@ArgsType() | ||
export class GetCollectionByIdArgs { | ||
@Field({ nullable: true }) | ||
id?: string; | ||
} |
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,22 @@ | ||
import { Field, InputType } from "type-graphql"; | ||
import type { WhereOptions } from "./whereOptions.js"; | ||
import {IdSearchOptions, NumberSearchOptions, StringSearchOptions} from "./searchOptions.js"; | ||
import { ContractSortOptions } from "./sortOptions.js"; | ||
import {Collection} from "../typeDefs/collectionTypeDefs.js"; | ||
import {CollectionOptions} from "./collectionOptions.js"; | ||
|
||
@InputType() | ||
export class BasicCollectionWhereInput implements WhereOptions<Collection> { | ||
@Field((_) => IdSearchOptions, { nullable: true }) | ||
id?: IdSearchOptions | null; | ||
@Field((_) => NumberSearchOptions, { nullable: true }) | ||
chain_id?: NumberSearchOptions | null; | ||
@Field((_) => StringSearchOptions, { nullable: true }) | ||
admin_id?: StringSearchOptions | null; | ||
} | ||
|
||
@InputType() | ||
export class CollectionFetchInput implements CollectionOptions<Collection> { | ||
@Field((_) => ContractSortOptions, { nullable: true }) | ||
by?: ContractSortOptions; | ||
} |
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,13 @@ | ||
import { | ||
AttestationSchemaSortOptions, | ||
AttestationSortOptions, | ||
ContractSortOptions, FractionSortOptions, | ||
HypercertSortOptions, | ||
MetadataSortOptions | ||
} from "./sortOptions.js"; | ||
|
||
|
||
export type CollectionOptions<T extends object> = { | ||
by?: HypercertSortOptions | ContractSortOptions | MetadataSortOptions | AttestationSortOptions | AttestationSchemaSortOptions | FractionSortOptions | null; | ||
} | ||
|
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,50 @@ | ||
import { Args, Field, Int, ObjectType, Query, Resolver } from "type-graphql"; | ||
import { inject, injectable } from "tsyringe"; | ||
import { Order } from "../typeDefs/orderTypeDefs.js"; | ||
import { SupabaseDataService } from "../../../services/SupabaseDataService.js"; | ||
import {Collection} from "../typeDefs/collectionTypeDefs.js"; | ||
import {GetCollectionArgs} from "../args/collectionArgs.js"; | ||
|
||
@ObjectType() | ||
export default class GetCollectionsResponse { | ||
@Field(() => [Collection], { nullable: true }) | ||
data?: Collection[]; | ||
|
||
@Field(() => Int, { nullable: true }) | ||
count?: number; | ||
} | ||
|
||
@injectable() | ||
@Resolver((_) => Order) | ||
class CollectionResolver { | ||
constructor( | ||
@inject(SupabaseDataService) | ||
private readonly supabaseService: SupabaseDataService, | ||
) {} | ||
|
||
@Query((_) => GetCollectionsResponse) | ||
async collections(@Args() args: GetCollectionArgs) { | ||
try { | ||
const res = await this.supabaseService.getCollections(args) | ||
|
||
const { data, error, count } = res; | ||
|
||
if (error) { | ||
console.warn( | ||
`[CollectionResolver::collections] Error fetching collections: `, | ||
error, | ||
); | ||
return { data }; | ||
} | ||
|
||
return { data, count: count ? count : data?.length }; | ||
} catch (e) { | ||
throw new Error( | ||
`[CollectionResolver::collections] Error fetching collections: ${(e as Error).message}`, | ||
); | ||
} | ||
} | ||
|
||
} | ||
|
||
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,21 @@ | ||
import { Field, ObjectType } from "type-graphql"; | ||
import { BasicTypeDef } from "./basicTypeDef.js"; | ||
import {GraphQLBigInt} from "graphql-scalars"; | ||
|
||
@ObjectType() | ||
class Collection extends BasicTypeDef { | ||
@Field() | ||
name?: string; | ||
@Field({name: "admin_address"}) | ||
admin_id?: string; | ||
@Field(() => GraphQLBigInt, {nullable: true}) | ||
chain_id?: number; | ||
@Field() | ||
background_image?: string; | ||
@Field() | ||
grayscale_image?: boolean; | ||
@Field() | ||
tile_border_color?: string; | ||
} | ||
|
||
export { Collection }; |
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.