Skip to content

Commit f069827

Browse files
authored
Merge pull request #148 from hypercerts-org/fix/query_fractions_view
Fix/query fractions view
2 parents 0c574cb + 402d9b8 commit f069827

File tree

10 files changed

+115
-101
lines changed

10 files changed

+115
-101
lines changed

schema.graphql

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ type Attestation {
8181
"""Encoded data of the attestation"""
8282
data: JSON
8383

84-
"""List of hypercerts related to the attestation"""
85-
hypercerts: [Hypercert!]
84+
"""Hypercert related to the attestation"""
85+
hypercert: HypercertBaseType
8686
id: ID!
8787

8888
"""Block number at which the attestation was last updated"""
@@ -398,16 +398,21 @@ type GetCollectionsResponse {
398398
data: [Collection!]
399399
}
400400

401+
"""Pointer to a contract deployed on a chain"""
401402
type GetContractsResponse {
402403
count: Int
403404
data: [Contract!]
404405
}
405406

407+
"""Fraction of an hypercert"""
406408
type GetFractionsResponse {
407409
count: Int
408410
data: [Fraction!]
409411
}
410412

413+
"""
414+
Hypercert with metadata, contract, orders, sales and fraction information
415+
"""
411416
type GetHypercertsResponse {
412417
count: Int
413418
data: [Hypercert!]

src/graphql/schemas/resolvers/attestationResolver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ class AttestationResolver extends AttestationBaseResolver {
3434
return await this.getAttestations(args);
3535
}
3636

37-
@FieldResolver({ nullable: true })
38-
async hypercerts(@Root() attestation: Attestation) {
37+
@FieldResolver()
38+
async hypercert(@Root() attestation: Attestation) {
3939
if (!attestation.data) return null;
4040

4141
const { success, data } = HypercertPointer.safeParse(attestation.data);

src/graphql/schemas/resolvers/baseTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export function createBaseResolver<T extends ClassType>(
137137
.execute(async (transaction) => {
138138
const dataRes = await transaction.executeQuery(queries.data);
139139
const countRes = await transaction.executeQuery(queries.count);
140+
140141
return {
141142
data: dataRes.rows,
142143
count: countRes.rows[0].count,

src/graphql/schemas/resolvers/contractResolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Contract } from "../typeDefs/contractTypeDefs.js";
33
import { GetContractsArgs } from "../args/contractArgs.js";
44
import { createBaseResolver, DataResponse } from "./baseTypes.js";
55

6-
@ObjectType()
6+
@ObjectType({ description: "Pointer to a contract deployed on a chain" })
77
export default class GetContractsResponse extends DataResponse(Contract) {}
88

99
const ContractBaseResolver = createBaseResolver("contract");

src/graphql/schemas/resolvers/fractionResolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { GetFractionsArgs } from "../args/fractionArgs.js";
1111
import { parseClaimOrFractionId } from "@hypercerts-org/sdk";
1212
import { createBaseResolver, DataResponse } from "./baseTypes.js";
1313

14-
@ObjectType()
14+
@ObjectType({ description: "Fraction of an hypercert" })
1515
export default class GetFractionsResponse extends DataResponse(Fraction) {}
1616

1717
const FractionBaseResolver = createBaseResolver("fraction");

src/graphql/schemas/resolvers/hypercertResolver.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import { Database } from "../../../types/supabaseData.js";
1717
import { createBaseResolver, DataResponse } from "./baseTypes.js";
1818
import "reflect-metadata";
1919

20-
@ObjectType()
20+
@ObjectType({
21+
description:
22+
"Hypercert with metadata, contract, orders, sales and fraction information",
23+
})
2124
export default class GetHypercertsResponse extends DataResponse(Hypercert) {}
2225

2326
const HypercertBaseResolver = createBaseResolver("hypercert");
@@ -66,12 +69,12 @@ class HypercertResolver extends HypercertBaseResolver {
6669

6770
@FieldResolver()
6871
async fractions(@Root() hypercert: Hypercert) {
69-
if (!hypercert.id) {
72+
if (!hypercert.hypercert_id) {
7073
return;
7174
}
7275

7376
return await this.getFractions(
74-
{ where: { hypercerts: { id: { eq: hypercert.id } } } },
77+
{ where: { hypercert_id: { eq: hypercert.hypercert_id } } },
7578
false,
7679
);
7780
}
Lines changed: 11 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,17 @@
1-
import { Field, ID, ObjectType } from "type-graphql";
2-
import { GraphQLJSON } from "graphql-scalars";
3-
import type { Json } from "../../../types/supabaseCaching.js";
4-
import { Hypercert } from "./hypercertTypeDefs.js";
5-
import { BasicTypeDef } from "./baseTypes/basicTypeDef.js";
6-
import { EthBigInt } from "../../scalars/ethBigInt.js";
1+
import { Field, ObjectType } from "type-graphql";
2+
import { AttestationBaseType } from "./baseTypes/attestationBaseType.js";
3+
import { HypercertBaseType } from "./baseTypes/hypercertBaseType.js";
74

8-
@ObjectType({ description: "Attestation on the Ethereum Attestation Service" })
9-
class Attestation extends BasicTypeDef {
10-
@Field(() => ID, {
5+
@ObjectType({
6+
description: "Attestation on the Ethereum Attestation Service",
7+
simpleResolvers: true,
8+
})
9+
class Attestation extends AttestationBaseType {
10+
@Field(() => HypercertBaseType, {
1111
nullable: true,
12-
description: "ID referencing the supported EAS schema in the database",
12+
description: "Hypercert related to the attestation",
1313
})
14-
supported_schemas_id?: string;
15-
@Field(() => ID, {
16-
nullable: true,
17-
description: "Unique identifier for the attestation on EAS",
18-
})
19-
uid?: string;
20-
21-
@Field(() => EthBigInt, {
22-
nullable: true,
23-
description: "Block number at which the attestation was created",
24-
})
25-
creation_block_number?: bigint | number | string;
26-
@Field(() => EthBigInt, {
27-
nullable: true,
28-
description: "Timestamp at which the attestation was created",
29-
})
30-
creation_block_timestamp?: bigint | number | string;
31-
@Field(() => EthBigInt, {
32-
nullable: true,
33-
description: "Block number at which the attestation was last updated",
34-
})
35-
last_update_block_number?: bigint | number | string;
36-
@Field(() => EthBigInt, {
37-
nullable: true,
38-
description: "Timestamp at which the attestation was last updated",
39-
})
40-
last_update_block_timestamp?: bigint | number | string;
41-
42-
@Field({
43-
nullable: true,
44-
description: "Address of the creator of the attestation",
45-
})
46-
attester?: string;
47-
@Field({
48-
nullable: true,
49-
description: "Address of the recipient of the attestation",
50-
})
51-
recipient?: string;
52-
@Field({
53-
nullable: true,
54-
description: "Address of the resolver contract for the attestation",
55-
})
56-
resolver?: string;
57-
@Field({
58-
nullable: true,
59-
description:
60-
"Unique identifier of the EAS schema used to create the attestation",
61-
})
62-
schema?: string;
63-
@Field(() => GraphQLJSON, {
64-
nullable: true,
65-
description: "Encoded data of the attestation",
66-
})
67-
data?: Json;
68-
69-
@Field(() => [Hypercert], {
70-
nullable: true,
71-
description: "List of hypercerts related to the attestation",
72-
})
73-
hypercerts?: Hypercert[];
14+
hypercert?: HypercertBaseType;
7415
}
7516

7617
export { Attestation };
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { Field, ID, ObjectType } from "type-graphql";
2+
import { BasicTypeDef } from "./basicTypeDef.js";
3+
import { EthBigInt } from "../../../scalars/ethBigInt.js";
4+
import type { Json } from "../../../../types/supabaseCaching.js";
5+
import { GraphQLJSON } from "graphql-scalars";
6+
7+
@ObjectType()
8+
class AttestationBaseType extends BasicTypeDef {
9+
@Field(() => ID, {
10+
nullable: true,
11+
description: "ID referencing the supported EAS schema in the database",
12+
})
13+
supported_schemas_id?: string;
14+
@Field(() => ID, {
15+
nullable: true,
16+
description: "Unique identifier for the attestation on EAS",
17+
})
18+
uid?: string;
19+
20+
@Field(() => EthBigInt, {
21+
nullable: true,
22+
description: "Block number at which the attestation was created",
23+
})
24+
creation_block_number?: bigint | number | string;
25+
@Field(() => EthBigInt, {
26+
nullable: true,
27+
description: "Timestamp at which the attestation was created",
28+
})
29+
creation_block_timestamp?: bigint | number | string;
30+
@Field(() => EthBigInt, {
31+
nullable: true,
32+
description: "Block number at which the attestation was last updated",
33+
})
34+
last_update_block_number?: bigint | number | string;
35+
@Field(() => EthBigInt, {
36+
nullable: true,
37+
description: "Timestamp at which the attestation was last updated",
38+
})
39+
last_update_block_timestamp?: bigint | number | string;
40+
41+
@Field({
42+
nullable: true,
43+
description: "Address of the creator of the attestation",
44+
})
45+
attester?: string;
46+
@Field({
47+
nullable: true,
48+
description: "Address of the recipient of the attestation",
49+
})
50+
recipient?: string;
51+
@Field({
52+
nullable: true,
53+
description: "Address of the resolver contract for the attestation",
54+
})
55+
resolver?: string;
56+
@Field({
57+
nullable: true,
58+
description:
59+
"Unique identifier of the EAS schema used to create the attestation",
60+
})
61+
schema?: string;
62+
@Field(() => GraphQLJSON, {
63+
nullable: true,
64+
description: "Encoded data of the attestation",
65+
})
66+
data?: Json;
67+
}
68+
69+
export { AttestationBaseType };

src/services/SupabaseCachingService.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,17 @@ export class SupabaseCachingService {
110110
case "claims":
111111
return this.db
112112
.selectFrom("claims")
113-
.selectAll("claims")
113+
.selectAll("claims") // Select all columns from the claims table
114114
.$if(args.where?.metadata, (qb) =>
115115
qb.innerJoin("metadata", "metadata.uri", "claims.uri"),
116116
)
117117
.$if(args.where?.attestations, (qb) =>
118118
qb.innerJoin("attestations", "attestations.claims_id", "claims.id"),
119119
)
120120
.$if(args.where?.fractions, (qb) =>
121-
qb.innerJoin("fractions", "fractions.claims_id", "claims.id"),
121+
qb.innerJoin("fractions_view", (join) =>
122+
join.on("fractions_view.claims_id", "=", "claims.id"),
123+
),
122124
)
123125
.$if(args.where?.contract, (qb) =>
124126
qb.innerJoin("contracts", "contracts.id", "claims.contracts_id"),
@@ -127,12 +129,14 @@ export class SupabaseCachingService {
127129
return this.db.selectFrom("contracts").selectAll();
128130
case "fractions":
129131
case "fractions_view":
130-
return this.db
131-
.selectFrom("fractions_view")
132-
.selectAll()
133-
.$if(args.where?.hypercerts, (qb) =>
134-
qb.innerJoin("claims", "claims.id", "fractions_view.claims_id"),
135-
);
132+
return this.db.selectFrom("fractions_view").selectAll();
133+
// .$if(args.where?.hypercerts, (qb) =>
134+
// qb.leftJoin(
135+
// "claims",
136+
// "claims.hypercert_id",
137+
// "fractions_view.hypercert_id",
138+
// ),
139+
// );
136140
case "metadata":
137141
return this.db
138142
.selectFrom("metadata")
@@ -178,8 +182,8 @@ export class SupabaseCachingService {
178182
.select((expressionBuilder) => {
179183
return expressionBuilder.fn.countAll().as("count");
180184
});
181-
case "hypercerts":
182185
case "claims":
186+
case "hypercerts":
183187
return this.db
184188
.selectFrom("claims")
185189
.$if(args.where?.metadata, (qb) =>
@@ -205,9 +209,6 @@ export class SupabaseCachingService {
205209
case "fractions_view":
206210
return this.db
207211
.selectFrom("fractions_view")
208-
.$if(args.where?.hypercerts, (qb) =>
209-
qb.innerJoin("claims", "claims.id", "fractions_view.claims_id"),
210-
)
211212
.select((expressionBuilder) => {
212213
return expressionBuilder.fn.countAll().as("count");
213214
});

src/types/graphql-env.d.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -375,17 +375,11 @@ export type introspection = {
375375
"args": []
376376
},
377377
{
378-
"name": "hypercerts",
378+
"name": "hypercert",
379379
"type": {
380-
"kind": "LIST",
381-
"ofType": {
382-
"kind": "NON_NULL",
383-
"ofType": {
384-
"kind": "OBJECT",
385-
"name": "Hypercert",
386-
"ofType": null
387-
}
388-
}
380+
"kind": "OBJECT",
381+
"name": "HypercertBaseType",
382+
"ofType": null
389383
},
390384
"args": []
391385
},

0 commit comments

Comments
 (0)