-
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.
Merge pull request #64 from hypercerts-org/feature/expose-orders-in-g…
…raph Feature/expose orders in graph
- Loading branch information
Showing
14 changed files
with
1,225 additions
and
408 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 { BasicOrderWhereInput, OrderFetchInput } from "../inputs/orderInput.js"; | ||
|
||
@ArgsType() | ||
export class GetOrdersArgs extends PaginationArgs { | ||
@Field({ nullable: true }) | ||
where?: BasicOrderWhereInput; | ||
@Field({ nullable: true }) | ||
sort?: OrderFetchInput; | ||
} | ||
|
||
@ArgsType() | ||
export class GetOrderByIdArgs { | ||
@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,20 @@ | ||
import { Field, InputType } from "type-graphql"; | ||
import type { WhereOptions } from "./whereOptions.js"; | ||
import { IdSearchOptions, NumberSearchOptions } from "./searchOptions.js"; | ||
import type { OrderOptions } from "./orderOptions.js"; | ||
import { ContractSortOptions } from "./sortOptions.js"; | ||
import { Order } from "../typeDefs/orderTypeDefs.js"; | ||
|
||
@InputType() | ||
export class BasicOrderWhereInput implements WhereOptions<Order> { | ||
@Field((_) => IdSearchOptions, { nullable: true }) | ||
id?: IdSearchOptions | null; | ||
@Field((_) => NumberSearchOptions, { nullable: true }) | ||
chain_id?: NumberSearchOptions | null; | ||
} | ||
|
||
@InputType() | ||
export class OrderFetchInput implements OrderOptions<Order> { | ||
@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 |
---|---|---|
@@ -1,8 +1,17 @@ | ||
import {HypercertResolver} from "./hypercertResolver.js"; | ||
import {MetadataResolver} from "./metadataResolver.js"; | ||
import {ContractResolver} from "./contractResolver.js"; | ||
import {FractionResolver} from "./fractionResolver.js"; | ||
import {AttestationResolver} from "./attestationResolver.js"; | ||
import {AttestationSchemaResolver} from "./attestationSchemaResolver.js"; | ||
import { HypercertResolver } from "./hypercertResolver.js"; | ||
import { MetadataResolver } from "./metadataResolver.js"; | ||
import { ContractResolver } from "./contractResolver.js"; | ||
import { FractionResolver } from "./fractionResolver.js"; | ||
import { AttestationResolver } from "./attestationResolver.js"; | ||
import { AttestationSchemaResolver } from "./attestationSchemaResolver.js"; | ||
import { OrderResolver } from "./orderResolver.js"; | ||
|
||
export const resolvers = [ContractResolver, FractionResolver, MetadataResolver, HypercertResolver, AttestationResolver, AttestationSchemaResolver] as const; | ||
export const resolvers = [ | ||
ContractResolver, | ||
FractionResolver, | ||
MetadataResolver, | ||
HypercertResolver, | ||
AttestationResolver, | ||
AttestationSchemaResolver, | ||
OrderResolver, | ||
] as const; |
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 |
---|---|---|
@@ -1,43 +1,107 @@ | ||
import {Args, Field, Int, ObjectType, Query, Resolver} from "type-graphql"; | ||
import {inject, injectable} from "tsyringe"; | ||
import {SupabaseCachingService} from "../../../services/SupabaseCachingService.js"; | ||
import {Fraction} from "../typeDefs/fractionTypeDefs.js"; | ||
import {GetFractionArgs} from "../args/fractionArgs.js"; | ||
import { | ||
Args, | ||
Field, | ||
FieldResolver, | ||
Int, | ||
ObjectType, | ||
Query, | ||
Resolver, | ||
Root, | ||
} from "type-graphql"; | ||
import { inject, injectable } from "tsyringe"; | ||
import { SupabaseCachingService } from "../../../services/SupabaseCachingService.js"; | ||
import { Fraction } from "../typeDefs/fractionTypeDefs.js"; | ||
import { GetFractionArgs } from "../args/fractionArgs.js"; | ||
import { SupabaseDataService } from "../../../services/SupabaseDataService.js"; | ||
import { parseClaimOrFractionId } from "@hypercerts-org/sdk"; | ||
|
||
@ObjectType() | ||
export default class GetFractionsResponse { | ||
@Field(() => [Fraction], {nullable: true}) | ||
data?: Fraction[]; | ||
@Field(() => [Fraction], { nullable: true }) | ||
data?: Fraction[]; | ||
|
||
@Field(() => Int, {nullable: true}) | ||
count?: number; | ||
@Field(() => Int, { nullable: true }) | ||
count?: number; | ||
} | ||
|
||
@injectable() | ||
@Resolver(_ => Fraction) | ||
@Resolver((_) => Fraction) | ||
class FractionResolver { | ||
constructor( | ||
@inject(SupabaseCachingService) | ||
private readonly supabaseCachingService: SupabaseCachingService, | ||
@inject(SupabaseDataService) | ||
private readonly supabaseDataService: SupabaseDataService, | ||
) {} | ||
|
||
constructor( | ||
@inject(SupabaseCachingService) | ||
private readonly supabaseService: SupabaseCachingService) { | ||
@Query((_) => GetFractionsResponse) | ||
async fractions(@Args() args: GetFractionArgs) { | ||
try { | ||
const res = await this.supabaseCachingService.getFractions(args); | ||
|
||
const { data, error, count } = res; | ||
|
||
if (error) { | ||
console.warn( | ||
`[FractionResolver::fractions] Error fetching fractions: `, | ||
error, | ||
); | ||
} | ||
|
||
return { data, count }; | ||
} catch (e) { | ||
throw new Error( | ||
`[FractionResolver::fractions] Error fetching fractions: ${(e as Error).message}`, | ||
); | ||
} | ||
} | ||
|
||
@FieldResolver() | ||
async orders(@Root() fraction: Partial<Fraction>) { | ||
if (!fraction.hypercert_id) { | ||
return null; | ||
} | ||
|
||
@Query(_ => GetFractionsResponse) | ||
async fractions(@Args() args: GetFractionArgs) { | ||
try { | ||
const res = await this.supabaseService.getFractions(args); | ||
const { id } = parseClaimOrFractionId(fraction.hypercert_id); | ||
|
||
if (!id) { | ||
console.warn( | ||
`[FractionResolver::orders] Error parsing hypercert_id for fraction ${fraction.id}`, | ||
); | ||
return null; | ||
} | ||
|
||
try { | ||
const res = await this.supabaseDataService.getOrdersForFraction( | ||
id.toString(), | ||
); | ||
|
||
if (!res) { | ||
console.warn( | ||
`[FractionResolver::orders] Error fetching orders for fraction ${fraction.id}: `, | ||
res, | ||
); | ||
return { data: [] }; | ||
} | ||
|
||
const {data, error, count} = res; | ||
const { data, error, count } = res; | ||
|
||
if (error) { | ||
console.warn(`[FractionResolver::fractions] Error fetching fractions: `, error); | ||
} | ||
if (error) { | ||
console.warn( | ||
`[FractionResolver::orders] Error fetching orders for fraction ${fraction.id}: `, | ||
error, | ||
); | ||
return { data: [] }; | ||
} | ||
|
||
return {data, count}; | ||
} catch (e) { | ||
throw new Error(`[FractionResolver::fractions] Error fetching fractions: ${(e as Error).message}`) | ||
} | ||
return { data: data || [], count: count || 0 }; | ||
} catch (e) { | ||
const error = e as Error; | ||
throw new Error( | ||
`[FractionResolver::orders] Error fetching orders for fraction ${fraction.id}: ${error.message}`, | ||
); | ||
} | ||
} | ||
} | ||
|
||
export {FractionResolver}; | ||
export { FractionResolver }; |
Oops, something went wrong.