Skip to content

Commit

Permalink
Merge pull request #71 from hypercerts-org/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
bitbeckers authored Jun 12, 2024
2 parents c78aeb5 + 3e09a29 commit e14b210
Show file tree
Hide file tree
Showing 20 changed files with 519 additions and 294 deletions.
55 changes: 39 additions & 16 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ input AttestationFetchInput {

type AttestationSchema {
chain_id: BigInt
eas_schema_id: ID
id: ID!
records: [Attestation!]
resolver: String
revocable: Boolean
schema: String
uid: ID
}

input AttestationSchemaFetchInput {
Expand All @@ -44,11 +44,11 @@ input AttestationSchemaSortOptions {
input AttestationSchemaWhereInput {
attestations: BasicAttestationSchemaWhereInput
chain_id: NumberSearchOptions
eas_schema_id: StringSearchOptions
id: IdSearchOptions
resolver: StringSearchOptions
revocable: BooleanSearchOptions
schema: StringSearchOptions
uid: StringSearchOptions
}

input AttestationSortOptions {
Expand Down Expand Up @@ -79,11 +79,11 @@ input AttestationWhereInput {

input BasicAttestationSchemaWhereInput {
chain_id: NumberSearchOptions
eas_schema_id: StringSearchOptions
id: IdSearchOptions
resolver: StringSearchOptions
revocable: BooleanSearchOptions
schema: StringSearchOptions
uid: StringSearchOptions
}

input BasicAttestationWhereInput {
Expand All @@ -109,7 +109,8 @@ input BasicContractWhereInput {

input BasicFractionWhereInput {
creation_block_timestamp: NumberSearchOptions
hypercert_id: IdSearchOptions
hypercert_id: StringSearchOptions
id: IdSearchOptions
last_block_update_timestamp: NumberSearchOptions
owner_address: StringSearchOptions
token_id: NumberSearchOptions
Expand All @@ -118,6 +119,7 @@ input BasicFractionWhereInput {

input BasicHypercertWhereInput {
block_number: NumberSearchOptions
creator_address: StringSearchOptions
hypercert_id: StringSearchOptions
id: IdSearchOptions
owner_address: StringSearchOptions
Expand All @@ -129,6 +131,7 @@ input BasicMetadataWhereInput {
contributors: StringArraySearchOptions
creation_block_timestamp: NumberSearchOptions
description: StringSearchOptions
id: IdSearchOptions
impact_scope: StringArraySearchOptions
impact_timeframe_from: NumberSearchOptions
impact_timeframe_to: NumberSearchOptions
Expand Down Expand Up @@ -187,10 +190,12 @@ enum CountKeys {
scalar EthBigInt

type Fraction {
claims_id: String
creation_block_timestamp: BigInt
hypercert_id: ID
id: ID!
last_block_update_timestamp: BigInt
metadata: Metadata
orders: GetOrdersResponse
owner_address: String
units: EthBigInt
Expand All @@ -210,8 +215,9 @@ input FractionSortOptions {

input FractionWhereInput {
creation_block_timestamp: NumberSearchOptions
hypercert_id: IdSearchOptions
hypercert_id: StringSearchOptions
hypercerts: BasicHypercertWhereInput
id: IdSearchOptions
last_block_update_timestamp: NumberSearchOptions
owner_address: StringSearchOptions
token_id: NumberSearchOptions
Expand Down Expand Up @@ -243,6 +249,11 @@ type GetHypercertsResponse {
data: [Hypercert!]
}

type GetMetadataResponse {
count: Int
data: [Metadata!]
}

type GetOrdersResponse {
count: Int
data: [Order!]
Expand All @@ -253,6 +264,7 @@ type Hypercert {
block_number: BigInt
contract: Contract
contracts_id: ID
creator_address: String
fractions: GetFractionsResponse
hypercert_id: ID
id: ID!
Expand Down Expand Up @@ -284,6 +296,7 @@ input HypercertsWhereInput {
attestations: BasicAttestationWhereInput
block_number: NumberSearchOptions
contract: BasicContractWhereInput
creator_address: StringSearchOptions
fractions: BasicFractionWhereInput
hypercert_id: StringSearchOptions
id: IdSearchOptions
Expand All @@ -294,10 +307,7 @@ input HypercertsWhereInput {
}

input IdSearchOptions {
contains: ID
endsWith: ID
eq: ID
startsWith: ID
eq: UUID
}

"""
Expand Down Expand Up @@ -338,13 +348,21 @@ input MetadataSortOptions {
}

input MetadataWhereInput {
block_number: NumberSearchOptions
hypercert_id: StringSearchOptions
contributors: StringArraySearchOptions
creation_block_timestamp: NumberSearchOptions
description: StringSearchOptions
hypercerts: BasicHypercertWhereInput
id: IdSearchOptions
metadata: BasicMetadataWhereInput
owner_address: StringSearchOptions
token_id: NumberSearchOptions
impact_scope: StringArraySearchOptions
impact_timeframe_from: NumberSearchOptions
impact_timeframe_to: NumberSearchOptions
last_block_update_timestamp: NumberSearchOptions
name: StringSearchOptions
rights: StringArraySearchOptions
uri: StringSearchOptions
work_scope: StringArraySearchOptions
work_timeframe_from: NumberSearchOptions
work_timeframe_to: NumberSearchOptions
}

input NumberSearchOptions {
Expand Down Expand Up @@ -387,7 +405,7 @@ type Query {
contracts(count: CountKeys, first: Int, offset: Int, sort: ContractFetchInput, where: BasicContractWhereInput): GetContractsResponse!
fractions(count: CountKeys, first: Int, offset: Int, sort: FractionFetchInput, where: FractionWhereInput): GetFractionsResponse!
hypercerts(count: CountKeys, first: Int, offset: Int, sort: HypercertFetchInput, where: HypercertsWhereInput): GetHypercertsResponse!
metadata(count: CountKeys, first: Int, offset: Int, sort: MetadataFetchInput, where: MetadataWhereInput): [Metadata!]!
metadata(count: CountKeys, first: Int, offset: Int, sort: MetadataFetchInput, where: MetadataWhereInput): GetMetadataResponse!
orders(count: CountKeys, first: Int, offset: Int, sort: OrderFetchInput, where: BasicOrderWhereInput): GetOrdersResponse!
}

Expand All @@ -409,4 +427,9 @@ input StringSearchOptions {
endsWith: String
eq: String
startsWith: String
}
}

"""
A field whose value is a generic Universally Unique Identifier: https://en.wikipedia.org/wiki/Universally_unique_identifier.
"""
scalar UUID
3 changes: 2 additions & 1 deletion src/graphql/schemas/args/hypercertsArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {BasicContractWhereInput} from "../inputs/contractInput.js";
import {BasicMetadataWhereInput} from "../inputs/metadataInput.js";
import {BasicAttestationWhereInput} from "../inputs/attestationInput.js";
import {BasicFractionWhereInput} from "../inputs/fractionInput.js";
import {IdSearchOptions} from "../inputs/searchOptions.js";

@InputType()
export class HypercertsWhereInput extends BasicHypercertWhereInput {
Expand All @@ -29,7 +30,7 @@ export class GetHypercertArgs extends PaginationArgs {

@ArgsType()
export class GetHypercertByIdArgs {
@Field({nullable: true})
@Field(_ => IdSearchOptions, {nullable: true})
id?: string;
@Field({nullable: true})
hypercert_id?: string;
Expand Down
6 changes: 3 additions & 3 deletions src/graphql/schemas/args/metadataArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {PaginationArgs} from "./paginationArgs.js";
import {BasicHypercertWhereInput} from "../inputs/hypercertsInput.js";

@InputType()
export class MetadataWhereInput extends BasicHypercertWhereInput {
@Field(_ => BasicMetadataWhereInput, {nullable: true})
metadata?: BasicMetadataWhereInput;
export class MetadataWhereInput extends BasicMetadataWhereInput {
@Field(_ => BasicHypercertWhereInput, {nullable: true})
hypercerts?: BasicHypercertWhereInput;
}

@ArgsType()
Expand Down
2 changes: 1 addition & 1 deletion src/graphql/schemas/inputs/attestationSchemaInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class BasicAttestationSchemaWhereInput implements WhereOptions<Attestatio
@Field(_ => IdSearchOptions, {nullable: true})
id?: IdSearchOptions | null;
@Field(_ => StringSearchOptions, {nullable: true})
eas_schema_id?: StringSearchOptions | null;
uid?: StringSearchOptions | null;
@Field(_ => NumberSearchOptions, {nullable: true})
chain_id?: NumberSearchOptions | null;
@Field(_ => StringSearchOptions, {nullable: true})
Expand Down
6 changes: 3 additions & 3 deletions src/graphql/schemas/inputs/contractInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {ContractSortOptions} from "./sortOptions.js";
@InputType()
export class BasicContractWhereInput implements WhereOptions<Contract> {
@Field(_ => IdSearchOptions, {nullable: true})
id?: IdSearchOptions | null;
id?: IdSearchOptions;
@Field(_ => StringSearchOptions, {nullable: true})
contract_address?: StringSearchOptions | null;
contract_address?: StringSearchOptions;
@Field(_ => NumberSearchOptions, {nullable: true})
chain_id?: NumberSearchOptions | null;
chain_id?: NumberSearchOptions;
}


Expand Down
4 changes: 3 additions & 1 deletion src/graphql/schemas/inputs/fractionInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {FractionSortOptions} from "./sortOptions.js";
@InputType()
export class BasicFractionWhereInput implements WhereOptions<Fraction> {
@Field(_ => IdSearchOptions, {nullable: true})
hypercert_id?: IdSearchOptions
id?: IdSearchOptions;
@Field(_ => StringSearchOptions, {nullable: true})
hypercert_id?: StringSearchOptions
@Field(_ => NumberSearchOptions, {nullable: true})
creation_block_timestamp?: NumberSearchOptions;
@Field(_ => NumberSearchOptions, {nullable: true})
Expand Down
2 changes: 2 additions & 0 deletions src/graphql/schemas/inputs/hypercertsInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export class BasicHypercertWhereInput implements WhereOptions<Hypercert> {
@Field(_ => StringSearchOptions, {nullable: true})
owner_address?: StringSearchOptions;
@Field(_ => StringSearchOptions, {nullable: true})
creator_address?: StringSearchOptions;
@Field(_ => StringSearchOptions, {nullable: true})
uri?: StringSearchOptions;
@Field(_ => StringSearchOptions, {nullable: true})
hypercert_id?: StringSearchOptions;
Expand Down
5 changes: 3 additions & 2 deletions src/graphql/schemas/inputs/metadataInput.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import {Field, InputType} from "type-graphql";
import type {WhereOptions} from "./whereOptions.js";
import {NumberSearchOptions, StringArraySearchOptions, StringSearchOptions} from "./searchOptions.js";
import {IdSearchOptions, NumberSearchOptions, StringArraySearchOptions, StringSearchOptions} from "./searchOptions.js";
import {Metadata} from "../typeDefs/metadataTypeDefs.js";
import type {OrderOptions} from "./orderOptions.js";
import {MetadataSortOptions} from "./sortOptions.js";

@InputType()
export class BasicMetadataWhereInput implements WhereOptions<Metadata> {
@Field(_ => IdSearchOptions, {nullable: true})
id?: IdSearchOptions;
@Field(_ => StringSearchOptions, {nullable: true})
name?: StringSearchOptions | null;
@Field(_ => StringSearchOptions, {nullable: true})
Expand All @@ -33,7 +35,6 @@ export class BasicMetadataWhereInput implements WhereOptions<Metadata> {
impact_timeframe_from?: NumberSearchOptions | null;
@Field(_ => NumberSearchOptions, {nullable: true})
impact_timeframe_to?: NumberSearchOptions | null;

}

@InputType()
Expand Down
13 changes: 2 additions & 11 deletions src/graphql/schemas/inputs/searchOptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Field, ID, InputType} from "type-graphql";
import {GraphQLBigInt} from "graphql-scalars";
import {GraphQLBigInt, GraphQLUUID} from "graphql-scalars";

@InputType()
export class BooleanSearchOptions {
Expand All @@ -9,17 +9,8 @@ export class BooleanSearchOptions {

@InputType()
export class IdSearchOptions {
@Field(_ => ID, {nullable: true})
@Field(_ => GraphQLUUID, {nullable: true})
eq?: string;

@Field(_ => ID, {nullable: true})
contains?: string;

@Field(_ => ID, {nullable: true})
startsWith?: string;

@Field(_ => ID, {nullable: true})
endsWith?: string;
}

@InputType()
Expand Down
26 changes: 17 additions & 9 deletions src/graphql/schemas/resolvers/attestationResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import {inject, injectable} from "tsyringe";
import {SupabaseCachingService} from "../../../services/SupabaseCachingService.js";
import {GetAttestationArgs} from "../args/attestationArgs.js";
import {Attestation} from "../typeDefs/attestationTypeDefs.js";
import {z} from "zod";
import {isAddress} from "viem"

const HypercertPointer = z.object({
chain_id: z.coerce.bigint(),
contract_address: z.string().refine(isAddress, {message: 'Invalid contract address'}),
token_id: z.coerce.bigint()
});

@ObjectType()
export default class GetAttestationsResponse {
Expand Down Expand Up @@ -30,14 +38,16 @@ class AttestationResolver {
const {data, error, count} = res;

if (error) {
console.warn(`[AttestationResolver] Error fetching attestations: `, error);
console.warn(`[AttestationResolver] Errors found while fetching attestations: `, error);
return {data, count: null};
}

console.log(data);

const newData = data ? data.map(item => {
return {
...item,
attestation: item.data ? JSON.parse(item.data as string) : item.attestation,
attestation: item.data
};
}) : data;

Expand All @@ -54,13 +64,15 @@ class AttestationResolver {

const _att = attestation.data;

if (!isHypercertPointer(_att)) return null;
if (!HypercertPointer.safeParse(_att).success) return null;

const pointer = HypercertPointer.parse(_att);

try {
const res = await this.supabaseService.getHypercerts({
where: {
contract: {chain_id: {eq: BigInt(_att.chain_id)}, contract_address: {eq: _att.contract_address}},
token_id: {eq: BigInt(_att.token_id)}
contract: {chain_id: {eq: pointer.chain_id}, contract_address: {eq: pointer.contract_address}},
token_id: {eq: pointer.token_id}
}
})

Expand All @@ -84,10 +96,6 @@ class AttestationResolver {
}
}

function isHypercertPointer(obj: any): obj is { chain_id: string, contract_address: string, token_id: string } {
return obj && typeof obj.chain_id === 'string' && typeof obj.contract_address === 'string' && typeof obj.token_id === 'string';
}

export {
AttestationResolver
};
2 changes: 1 addition & 1 deletion src/graphql/schemas/resolvers/attestationSchemaResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class AttestationSchemaResolver {
return data.map((attestation) => {
return {
...attestation,
attestation: JSON.parse(attestation.data as string)
attestation: attestation.data
}
});
} catch (e) {
Expand Down
Loading

0 comments on commit e14b210

Please sign in to comment.