@@ -2,15 +2,15 @@ import { inject, injectable } from "tsyringe";
22import { Args , FieldResolver , Query , Resolver , Root } from "type-graphql" ;
33import { getAddress , isAddress } from "viem" ;
44import { z } from "zod" ;
5- import { AttestationService } from "../../database/entities/AttestationEntityService.js" ;
6- import { AttestationSchemaService } from "../../database/entities/AttestationSchemaEntityService.js" ;
7- import { HypercertsService } from "../../database/entities/HypercertsEntityService.js" ;
8- import { MetadataService } from "../../database/entities/MetadataEntityService.js" ;
95import { GetAttestationsArgs } from "../../../graphql/schemas/args/attestationArgs.js" ;
106import {
117 Attestation ,
128 GetAttestationsResponse ,
139} from "../../../graphql/schemas/typeDefs/attestationTypeDefs.js" ;
10+ import { AttestationService } from "../../database/entities/AttestationEntityService.js" ;
11+ import { AttestationSchemaService } from "../../database/entities/AttestationSchemaEntityService.js" ;
12+ import { HypercertsService } from "../../database/entities/HypercertsEntityService.js" ;
13+ import { MetadataService } from "../../database/entities/MetadataEntityService.js" ;
1414
1515/**
1616 * Schema for validating hypercert pointer data in attestations.
@@ -70,9 +70,9 @@ const HypercertPointer = z.object({
7070 * - Field resolution for metadata associated with the attested hypercert
7171 *
7272 * Error handling:
73- * - Invalid attestation data returns undefined for related fields
73+ * - Invalid attestation data returns null for related fields
7474 * - Database errors are propagated to the GraphQL layer
75- * - Schema validation errors result in undefined hypercert IDs
75+ * - Schema validation errors result in null hypercert IDs
7676 *
7777 * @injectable Marks the class as injectable for dependency injection with tsyringe
7878 * @resolver Marks the class as a GraphQL resolver for the Attestation type
@@ -107,7 +107,6 @@ class AttestationResolver {
107107 * @returns A promise that resolves to an object containing:
108108 * - data: Array of attestations matching the query
109109 * - count: Total number of matching attestations
110- * @throws {Error } If the database query fails
111110 *
112111 * Filtering supports:
113112 * - Attestation fields (id, supported_schemas_id, etc.)
@@ -137,7 +136,14 @@ class AttestationResolver {
137136 */
138137 @Query ( ( ) => GetAttestationsResponse )
139138 async attestations ( @Args ( ) args : GetAttestationsArgs ) {
140- return await this . attestationService . getAttestations ( args ) ;
139+ try {
140+ return await this . attestationService . getAttestations ( args ) ;
141+ } catch ( e ) {
142+ console . error (
143+ `[AttestationResolver::attestations] Error fetching attestations: ${ ( e as Error ) . message } ` ,
144+ ) ;
145+ return null ;
146+ }
141147 }
142148
143149 /**
@@ -152,7 +158,6 @@ class AttestationResolver {
152158 * - attestation.data is null/undefined
153159 * - hypercert ID cannot be extracted from data
154160 * - no matching hypercert is found
155- * @throws {Error } If the hypercert service query fails
156161 *
157162 * @example
158163 * Query with hypercert field:
@@ -173,19 +178,26 @@ class AttestationResolver {
173178 */
174179 @FieldResolver ( )
175180 async hypercert ( @Root ( ) attestation : Attestation ) {
176- if ( ! attestation . data ) return ;
181+ try {
182+ if ( ! attestation . data ) return null ;
177183
178- const attested_hypercert_id = this . getHypercertIdFromAttestationData (
179- attestation . data ,
180- ) ;
184+ const attested_hypercert_id = this . getHypercertIdFromAttestationData (
185+ attestation . data ,
186+ ) ;
181187
182- if ( ! attested_hypercert_id ) return ;
188+ if ( ! attested_hypercert_id ) return null ;
183189
184- return await this . hypercertService . getHypercert ( {
185- where : {
186- hypercert_id : { eq : attested_hypercert_id } ,
187- } ,
188- } ) ;
190+ return await this . hypercertService . getHypercert ( {
191+ where : {
192+ hypercert_id : { eq : attested_hypercert_id } ,
193+ } ,
194+ } ) ;
195+ } catch ( e ) {
196+ console . error (
197+ `[AttestationResolver::hypercert] Error fetching hypercert: ${ ( e as Error ) . message } ` ,
198+ ) ;
199+ return null ;
200+ }
189201 }
190202
191203 /**
@@ -196,7 +208,6 @@ class AttestationResolver {
196208 * @returns A promise that resolves to:
197209 * - The associated schema data if found
198210 * - undefined if no schema ID is present
199- * @throws {Error } If the schema service query fails
200211 *
201212 * @example
202213 * Query with schema field:
@@ -219,13 +230,20 @@ class AttestationResolver {
219230 */
220231 @FieldResolver ( )
221232 async eas_schema ( @Root ( ) attestation : Attestation ) {
222- if ( ! attestation . supported_schemas_id ) return ;
233+ try {
234+ if ( ! attestation . supported_schemas_id ) return null ;
223235
224- return await this . attestationSchemaService . getAttestationSchema ( {
225- where : {
226- id : { eq : attestation . supported_schemas_id } ,
227- } ,
228- } ) ;
236+ return await this . attestationSchemaService . getAttestationSchema ( {
237+ where : {
238+ id : { eq : attestation . supported_schemas_id } ,
239+ } ,
240+ } ) ;
241+ } catch ( e ) {
242+ console . error (
243+ `[AttestationResolver::eas_schema] Error fetching eas_schema: ${ ( e as Error ) . message } ` ,
244+ ) ;
245+ return null ;
246+ }
229247 }
230248
231249 /**
@@ -263,17 +281,24 @@ class AttestationResolver {
263281 //TODO: Should this be part of the resolved hypercert data?
264282 @FieldResolver ( )
265283 async metadata ( @Root ( ) attestation : Attestation ) {
266- if ( ! attestation . data ) return ;
284+ try {
285+ if ( ! attestation . data ) return null ;
267286
268- const attested_hypercert_id = this . getHypercertIdFromAttestationData (
269- attestation . data ,
270- ) ;
287+ const attested_hypercert_id = this . getHypercertIdFromAttestationData (
288+ attestation . data ,
289+ ) ;
271290
272- if ( ! attested_hypercert_id ) return ;
291+ if ( ! attested_hypercert_id ) return null ;
273292
274- return await this . metadataService . getMetadataSingle ( {
275- where : { hypercerts : { hypercert_id : { eq : attested_hypercert_id } } } ,
276- } ) ;
293+ return await this . metadataService . getMetadataSingle ( {
294+ where : { hypercerts : { hypercert_id : { eq : attested_hypercert_id } } } ,
295+ } ) ;
296+ } catch ( e ) {
297+ console . error (
298+ `[AttestationResolver::metadata] Error fetching metadata: ${ ( e as Error ) . message } ` ,
299+ ) ;
300+ return null ;
301+ }
277302 }
278303
279304 /**
@@ -299,17 +324,22 @@ class AttestationResolver {
299324 * getHypercertIdFromAttestationData(null) // returns undefined
300325 * ```
301326 */
302- getHypercertIdFromAttestationData (
303- attestationData : unknown ,
304- ) : string | undefined {
305- if ( ! attestationData ) return ;
327+ getHypercertIdFromAttestationData ( attestationData : unknown ) : string | null {
328+ try {
329+ if ( ! attestationData ) return null ;
306330
307- const parseResult = HypercertPointer . safeParse ( attestationData ) ;
331+ const parseResult = HypercertPointer . safeParse ( attestationData ) ;
308332
309- if ( ! parseResult . success ) return ;
333+ if ( ! parseResult . success ) return null ;
310334
311- const { chain_id, contract_address, token_id } = parseResult . data ;
312- return `${ chain_id . toString ( ) } -${ getAddress ( contract_address ) } -${ token_id . toString ( ) } ` ;
335+ const { chain_id, contract_address, token_id } = parseResult . data ;
336+ return `${ chain_id . toString ( ) } -${ getAddress ( contract_address ) } -${ token_id . toString ( ) } ` ;
337+ } catch ( e ) {
338+ console . error (
339+ `[AttestationResolver::getHypercertIdFromAttestationData] Error parsing hypercert ID: ${ ( e as Error ) . message } ` ,
340+ ) ;
341+ return null ;
342+ }
313343 }
314344}
315345
0 commit comments