Skip to content

Commit b4259aa

Browse files
committed
feat(attestationschema): restructure attestation schema resolver and related components
Refactored the attestation schema resolver and related components to improve code organization and maintainability: - Moved AttestationSchemaResolver from graphql to services directory - Updated import paths in composed resolver and type definitions - Enhanced type definitions with comprehensive documentation - Added detailed JSDoc comments for classes and methods - Introduced comprehensive test coverage for AttestationSchemaService, SupportedSchemasQueryStrategy, and AttestationSchemaResolver - Improved type safety and code clarity across related files
1 parent 68e8532 commit b4259aa

10 files changed

Lines changed: 606 additions & 38 deletions

File tree

src/graphql/schemas/resolvers/attestationSchemaResolver.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/graphql/schemas/resolvers/composed.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { MetadataResolver } from "./metadataResolver.js";
33
import { ContractResolver } from "./contractResolver.js";
44
import { FractionResolver } from "./fractionResolver.js";
55
import { AttestationResolver } from "../../../services/graphql/resolvers/attestationResolver.js";
6-
import { AttestationSchemaResolver } from "./attestationSchemaResolver.js";
6+
import { AttestationSchemaResolver } from "../../../services/graphql/resolvers/attestationSchemaResolver.js";
77
import { OrderResolver } from "./orderResolver.js";
88
import { HyperboardResolver } from "./hyperboardResolver.js";
99
import { AllowlistRecordResolver } from "../../../services/graphql/resolvers/allowlistRecordResolver.js";

src/graphql/schemas/typeDefs/attestationSchemaTypeDefs.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,39 @@ import { DataResponse } from "../../../lib/graphql/DataResponse.js";
33
import { GetAttestationsResponse } from "./attestationTypeDefs.js";
44
import { AttestationSchemaBaseType } from "./baseTypes/attestationSchemaBaseType.js";
55

6+
/**
7+
* GraphQL object type representing an EAS (Ethereum Attestation Service) schema.
8+
* Extends the base type with additional fields for related attestations.
9+
*
10+
* This type provides:
11+
* - All fields from AttestationSchemaBaseType (id, chain_id, schema, resolver, revocable, uid)
12+
* - Additional field for accessing related attestations
13+
*
14+
* @extends {AttestationSchemaBaseType}
15+
*/
616
@ObjectType({
717
description: "Supported EAS attestation schemas and their related records",
818
})
919
export class AttestationSchema extends AttestationSchemaBaseType {
20+
/**
21+
* Collection of attestations that use this schema.
22+
* Includes both the attestation records and a total count.
23+
*/
1024
@Field(() => GetAttestationsResponse, {
1125
description: "List of attestations related to the attestation schema",
1226
})
1327
attestations?: GetAttestationsResponse | null;
1428
}
1529

30+
/**
31+
* GraphQL response type for attestation schema queries.
32+
* Wraps an array of AttestationSchema objects with pagination information.
33+
*
34+
* This type provides:
35+
* - data: Array of attestation schemas
36+
* - count: Total number of schemas matching the query
37+
*/
1638
@ObjectType()
17-
export default class GetAttestationsSchemaResponse extends DataResponse(
39+
export class GetAttestationsSchemaResponse extends DataResponse(
1840
AttestationSchema,
1941
) {}

src/graphql/schemas/typeDefs/baseTypes/attestationSchemaBaseType.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,63 @@ import { Field, ID, ObjectType } from "type-graphql";
22
import { EthBigInt } from "../../../scalars/ethBigInt.js";
33
import { BasicTypeDef } from "./basicTypeDef.js";
44

5+
/**
6+
* Base GraphQL object type for EAS (Ethereum Attestation Service) schemas.
7+
* Provides the core fields that define an attestation schema.
8+
*
9+
* This type provides:
10+
* - Basic identification fields (id from BasicTypeDef)
11+
* - Schema-specific fields (chain_id, uid, schema, resolver, revocable)
12+
*
13+
* Used as a base class for more specific schema types that may add additional fields.
14+
*
15+
* @extends {BasicTypeDef}
16+
*/
517
@ObjectType({
618
description: "Supported EAS attestation schemas and their related records",
719
})
820
class AttestationSchemaBaseType extends BasicTypeDef {
21+
/**
22+
* Chain ID where this schema is supported.
23+
* Can be represented as a bigint, number, or string.
24+
*/
925
@Field(() => EthBigInt, {
1026
description:
1127
"Chain ID of the chains where the attestation schema is supported",
1228
})
1329
chain_id?: bigint | number | string;
30+
31+
/**
32+
* Unique identifier for the schema on EAS.
33+
* This is different from the database id field.
34+
*/
1435
@Field(() => ID, {
1536
description: "Unique identifier for the attestation schema",
1637
})
1738
uid?: string;
39+
40+
/**
41+
* Address of the resolver contract for this schema.
42+
* The resolver contract handles the validation and processing of attestations.
43+
*/
1844
@Field({
1945
description: "Address of the resolver contract for the attestation schema",
2046
})
2147
resolver?: string;
48+
49+
/**
50+
* Whether attestations using this schema can be revoked.
51+
* If true, attesters can revoke their attestations after creation.
52+
*/
2253
@Field({
2354
description: "Whether the attestation schema is revocable",
2455
})
2556
revocable?: boolean;
57+
58+
/**
59+
* String representation of the schema definition.
60+
* Defines the structure and types of data that can be attested.
61+
*/
2662
@Field({
2763
description: "String representation of the attestation schema",
2864
})

src/services/database/entities/AttestationSchemaEntityService.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,32 @@ import {
88
type EntityService,
99
} from "./EntityServiceFactory.js";
1010

11+
/** Type representing a selected attestation schema record from the database */
1112
export type AttestationSchemaSelect = Selectable<
1213
CachingDatabase["supported_schemas"]
1314
>;
1415

16+
/**
17+
* Service class for managing attestation schema entities in the database.
18+
* Handles CRUD operations for EAS (Ethereum Attestation Service) schemas.
19+
*
20+
* This service provides methods to:
21+
* - Retrieve multiple attestation schemas with filtering and pagination
22+
* - Retrieve a single attestation schema by its criteria
23+
*
24+
* @injectable Marks the class as injectable for dependency injection with tsyringe
25+
*/
1526
@injectable()
1627
export class AttestationSchemaService {
1728
private entityService: EntityService<
1829
CachingDatabase["supported_schemas"],
1930
GetAttestationSchemasArgs
2031
>;
2132

33+
/**
34+
* Creates a new instance of AttestationSchemaService.
35+
* Initializes the underlying entity service for database operations.
36+
*/
2237
constructor() {
2338
this.entityService = createEntityService<
2439
CachingDatabase,
@@ -27,10 +42,47 @@ export class AttestationSchemaService {
2742
>("supported_schemas", "AttestationSchemaEntityService", kyselyCaching);
2843
}
2944

45+
/**
46+
* Retrieves multiple attestation schemas based on provided arguments.
47+
*
48+
* @param args - Query arguments for filtering and pagination
49+
* @returns A promise that resolves to an object containing:
50+
* - data: Array of attestation schemas matching the query
51+
* - count: Total number of matching schemas
52+
* @throws {Error} If the database query fails
53+
*
54+
* @example
55+
* ```typescript
56+
* const result = await service.getAttestationSchemas({
57+
* where: { id: { eq: "schema-id" } }
58+
* });
59+
* console.log(result.data); // Array of matching schemas
60+
* console.log(result.count); // Total count
61+
* ```
62+
*/
3063
async getAttestationSchemas(args: GetAttestationSchemasArgs) {
3164
return this.entityService.getMany(args);
3265
}
3366

67+
/**
68+
* Retrieves a single attestation schema based on provided arguments.
69+
*
70+
* @param args - Query arguments for filtering
71+
* @returns A promise that resolves to:
72+
* - The matching attestation schema if found
73+
* - undefined if no schema matches the criteria
74+
* @throws {Error} If the database query fails
75+
*
76+
* @example
77+
* ```typescript
78+
* const schema = await service.getAttestationSchema({
79+
* where: { id: { eq: "schema-id" } }
80+
* });
81+
* if (schema) {
82+
* console.log("Found schema:", schema);
83+
* }
84+
* ```
85+
*/
3486
async getAttestationSchema(args: GetAttestationSchemasArgs) {
3587
return this.entityService.getSingle(args);
3688
}

src/services/database/strategies/SupportedSchemasQueryStrategy.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,52 @@ import { CachingDatabase } from "../../../types/kyselySupabaseCaching.js";
33
import { QueryStrategy } from "./QueryStrategy.js";
44

55
/**
6-
* Strategy for querying supported schemas
7-
* Handles joins with attestations and eas_schema tables
6+
* Strategy for querying supported EAS (Ethereum Attestation Service) schemas.
7+
* Provides a simple query interface for the supported_schemas table.
8+
*
9+
* This strategy extends the base QueryStrategy to provide schema-specific query building.
10+
* It handles basic data retrieval and counting operations without complex joins or filtering.
11+
*
12+
* @template CachingDatabase - The database type containing the supported_schemas table
813
*/
914
export class SupportedSchemasQueryStrategy extends QueryStrategy<
1015
CachingDatabase,
1116
"supported_schemas"
1217
> {
1318
protected readonly tableName = "supported_schemas" as const;
1419

20+
/**
21+
* Builds a query to retrieve supported schema data.
22+
* Returns a simple SELECT query that retrieves all columns from the supported_schemas table.
23+
*
24+
* @param db - Kysely database instance
25+
* @returns A query builder for retrieving supported schema data
26+
*
27+
* @example
28+
* ```typescript
29+
* // Basic query to select all supported schemas
30+
* buildDataQuery(db);
31+
* // SELECT * FROM supported_schemas
32+
* ```
33+
*/
1534
buildDataQuery(db: Kysely<CachingDatabase>) {
1635
return db.selectFrom(this.tableName).selectAll();
1736
}
1837

38+
/**
39+
* Builds a query to count supported schemas.
40+
* Returns a simple COUNT query for the supported_schemas table.
41+
*
42+
* @param db - Kysely database instance
43+
* @returns A query builder for counting supported schemas
44+
*
45+
* @example
46+
* ```typescript
47+
* // Count all supported schemas
48+
* buildCountQuery(db);
49+
* // SELECT COUNT(*) as count FROM supported_schemas
50+
* ```
51+
*/
1952
buildCountQuery(db: Kysely<CachingDatabase>) {
2053
return db.selectFrom(this.tableName).select((eb) => {
2154
return eb.fn.countAll().as("count");

0 commit comments

Comments
 (0)