Skip to content

Commit 5d25f5c

Browse files
committed
fix(hyperboard): update hyperboard response types
Makes the hyperboard owners and sections response type consistent with other return types.
1 parent de397b1 commit 5d25f5c

File tree

5 files changed

+54
-62
lines changed

5 files changed

+54
-62
lines changed

src/graphql/schemas/typeDefs/hyperboardTypeDefs.ts

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,65 +17,24 @@ export class GetHyperboardOwnersResponse extends DataResponse(
1717
) {}
1818

1919
@ObjectType({
20-
description: "Hyperboard of hypercerts for reference and display purposes",
21-
})
22-
export class Hyperboard extends BasicTypeDef {
23-
@Field({ description: "Name of the hyperboard" })
24-
name?: string;
25-
@Field(() => [EthBigInt], {
26-
nullable: true,
27-
description: "Chain ID of the hyperboard",
28-
})
29-
chain_ids?: (bigint | number | string)[];
30-
@Field({ nullable: true, description: "Background image of the hyperboard" })
31-
background_image?: string;
32-
@Field({
33-
nullable: true,
34-
description:
35-
"Whether the hyperboard should be rendered as a grayscale image",
36-
})
37-
grayscale_images?: boolean;
38-
@Field({
39-
nullable: true,
40-
description: "Color of the borders of the hyperboard",
41-
})
42-
tile_border_color?: string;
43-
44-
@Field(() => GetUsersResponse)
45-
admins?: GetUsersResponse;
46-
47-
@Field(() => [SectionResponseType])
48-
sections?: SectionResponseType[];
49-
50-
@Field(() => GetHyperboardOwnersResponse)
51-
owners?: GetHyperboardOwnersResponse;
52-
}
53-
54-
@ObjectType({})
55-
export class SectionResponseType {
56-
@Field(() => [Section])
57-
data?: Section[];
58-
59-
@Field()
60-
count?: number;
61-
}
62-
63-
@ObjectType({
64-
description: "Section representing a collection within a hyperboard",
20+
description:
21+
"Section representing one or more collectionswithin a hyperboard",
6522
})
6623
export class Section {
6724
@Field()
6825
label?: string;
6926

70-
@Field(() => Collection)
71-
collection?: Collection;
27+
@Field(() => [Collection])
28+
collections?: Collection[];
7229

7330
@Field(() => [SectionEntry])
7431
entries?: SectionEntry[];
7532

7633
@Field(() => GetHyperboardOwnersResponse)
7734
owners?: GetHyperboardOwnersResponse;
7835
}
36+
@ObjectType({})
37+
export class GetSectionsResponse extends DataResponse(Section) {}
7938

8039
@ObjectType()
8140
class SectionEntryOwner extends User {
@@ -111,5 +70,40 @@ class SectionEntry {
11170
owners?: GetSectionEntryOwnersResponse;
11271
}
11372

73+
@ObjectType({
74+
description: "Hyperboard of hypercerts for reference and display purposes",
75+
})
76+
export class Hyperboard extends BasicTypeDef {
77+
@Field({ description: "Name of the hyperboard" })
78+
name?: string;
79+
@Field(() => [EthBigInt], {
80+
nullable: true,
81+
description: "Chain ID of the hyperboard",
82+
})
83+
chain_ids?: (bigint | number | string)[];
84+
@Field({ nullable: true, description: "Background image of the hyperboard" })
85+
background_image?: string;
86+
@Field({
87+
nullable: true,
88+
description:
89+
"Whether the hyperboard should be rendered as a grayscale image",
90+
})
91+
grayscale_images?: boolean;
92+
@Field({
93+
nullable: true,
94+
description: "Color of the borders of the hyperboard",
95+
})
96+
tile_border_color?: string;
97+
98+
@Field(() => GetUsersResponse)
99+
admins?: GetUsersResponse;
100+
101+
@Field(() => GetSectionsResponse)
102+
sections?: GetSectionsResponse;
103+
104+
@Field(() => GetHyperboardOwnersResponse)
105+
owners?: GetHyperboardOwnersResponse;
106+
}
107+
114108
@ObjectType()
115109
export class GetHyperboardsResponse extends DataResponse(Hyperboard) {}

src/services/graphql/resolvers/hyperboardResolver.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
GetHyperboardsResponse,
99
Hyperboard,
1010
HyperboardOwner,
11-
SectionResponseType,
11+
GetSectionsResponse,
1212
} from "../../../graphql/schemas/typeDefs/hyperboardTypeDefs.js";
1313
import GetUsersResponse from "../../../graphql/schemas/typeDefs/userTypeDefs.js";
1414
import { CachingDatabase } from "../../../types/kyselySupabaseCaching.js";
@@ -151,7 +151,7 @@ class HyperboardResolver {
151151
* }
152152
* ```
153153
*/
154-
@FieldResolver(() => [SectionResponseType])
154+
@FieldResolver(() => GetSectionsResponse)
155155
async sections(@Root() hyperboard: Hyperboard) {
156156
if (!hyperboard.id) {
157157
console.error(
@@ -253,7 +253,7 @@ class HyperboardResolver {
253253
}),
254254
);
255255

256-
return [{ data: sections, count: sections.length }];
256+
return { data: sections, count: sections.length };
257257
} catch (e) {
258258
console.error(
259259
`[HyperboardResolver::sections] Error fetching sections for hyperboard ${hyperboard.id}: ${(e as Error).message}`,
@@ -280,8 +280,7 @@ class HyperboardResolver {
280280
return [];
281281
}
282282

283-
const allSections = sections.flatMap((section) => section.data || []);
284-
return processSectionsToHyperboardOwnership(allSections);
283+
return processSectionsToHyperboardOwnership(sections.data);
285284
} catch (e) {
286285
console.error(
287286
`[HyperboardResolver::owners] Error fetching owners for hyperboard ${hyperboard.id}: ${(e as Error).message}`,

src/utils/processCollectionToSection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ export const processCollectionToSection = ({
353353
.value();
354354

355355
return {
356-
collection,
356+
collections: [collection],
357357
label: collection.name,
358358
entries: entries || [],
359359
owners: {

test/services/graphql/resolvers/hyperboardResolver.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,21 +248,20 @@ describe("HyperboardResolver", () => {
248248
throw new Error("Result should not be null");
249249
}
250250

251-
expect(result).toHaveLength(1);
252-
expect(result[0].data).toHaveLength(1);
251+
expect(result.data).toHaveLength(1);
252+
expect(result.data[0].collections).toHaveLength(1);
253253
expect(
254254
mockHyperboardService.getHyperboardCollections,
255255
).toHaveBeenCalledWith(mockHyperboard.id);
256256

257257
// Verify the section data structure
258-
const section = result[0].data[0];
258+
const section = result.data[0];
259259
expect(section).toHaveProperty("label");
260-
expect(section).toHaveProperty("collection");
260+
expect(section).toHaveProperty("collections");
261261
expect(section).toHaveProperty("entries");
262262
expect(section).toHaveProperty("owners");
263-
expect(section.collection).toBeDefined();
264-
expect(section.entries).toBeInstanceOf(Array);
265-
expect(section.owners).toBeInstanceOf(Array);
263+
expect(section.collections).toBeInstanceOf(Array);
264+
expect(section.owners?.data).toHaveLength(2);
266265
});
267266

268267
it("should return empty sections when hyperboard has no id", async () => {

test/utils/testUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ export function generateMockHyperboard(
637637
grayscale_images: boolean;
638638
tile_border_color: string;
639639
admins: { data: ReturnType<typeof generateMockUser>[]; count: number };
640-
sections: Array<{
640+
sections: {
641641
data: Array<{
642642
label: string;
643643
collection: ReturnType<typeof generateMockCollection>;
@@ -666,7 +666,7 @@ export function generateMockHyperboard(
666666
}>;
667667
}>;
668668
count: number;
669-
}>;
669+
};
670670
owners: {
671671
data: Array<
672672
ReturnType<typeof generateMockUser> & { percentage_owned: number }

0 commit comments

Comments
 (0)