Skip to content

Commit

Permalink
Merge pull request #210 from hypercerts-org/feat/expose-blueprints-hy…
Browse files Browse the repository at this point in the history
…percerts-relation

Feat/expose blueprints hypercerts relation
  • Loading branch information
pheuberger authored Jan 21, 2025
2 parents 59dc9f2 + dfa2d7c commit 32c6505
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
7 changes: 6 additions & 1 deletion commitlintrc.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export default { extends: ["@commitlint/config-conventional"] };
export default {
extends: ["@commitlint/config-conventional"],
rules: {
"body-max-line-length": [2, "always", 500],
},
};
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ type Blueprint {
admins: [User!]!
created_at: String!
form_values: JSON!
hypercerts: GetHypercertsResponse!
id: Float!
minted: Boolean!
minter_address: String!
Expand Down
28 changes: 26 additions & 2 deletions src/graphql/schemas/resolvers/blueprintResolver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Args, ObjectType, Query, Resolver } from "type-graphql";
import {
Args,
FieldResolver,
ObjectType,
Query,
Resolver,
Root,
} from "type-graphql";
import { createBaseResolver, DataResponse } from "./baseTypes.js";
import { Blueprint } from "../typeDefs/blueprintTypeDefs.js";
import { GetBlueprintArgs } from "../args/blueprintArgs.js";
Expand All @@ -23,11 +30,18 @@ class BlueprintResolver extends BlueprintBaseResolver {
.groupBy("id")
.map((blueprints) => {
const admins = blueprints.map(
({ admin_address, admin_chain_id, avatar, display_name }) => ({
({
admin_address,
admin_chain_id,
avatar,
display_name,
hypercert_ids,
}) => ({
address: admin_address,
chain_id: admin_chain_id,
avatar,
display_name,
hypercert_ids,
}),
);
return {
Expand All @@ -41,6 +55,16 @@ class BlueprintResolver extends BlueprintBaseResolver {
count,
};
}

@FieldResolver()
async hypercerts(@Root() blueprint: Blueprint) {
const hypercertIds = blueprint.hypercert_ids;
const { data: hypercerts, count } = await this.getHypercerts({
where: { hypercert_id: { in: hypercertIds } },
});

return { data: hypercerts, count };
}
}

export { BlueprintResolver };
7 changes: 7 additions & 0 deletions src/graphql/schemas/typeDefs/blueprintTypeDefs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Field, ObjectType } from "type-graphql";
import { GraphQLJSON } from "graphql-scalars";
import { User } from "./userTypeDefs.js";
import GetHypercertsResponse from "../resolvers/hypercertResolver.js";

@ObjectType()
class Blueprint {
Expand All @@ -21,6 +22,12 @@ class Blueprint {

@Field(() => [User])
admins?: User[];

@Field(() => GetHypercertsResponse)
hypercerts?: GetHypercertsResponse;

// Internal field, not queryable
hypercert_ids?: string[];
}

export { Blueprint };

0 comments on commit 32c6505

Please sign in to comment.