Skip to content

Commit

Permalink
changed parent and parentHash types to more semantically correct format
Browse files Browse the repository at this point in the history
  • Loading branch information
nil-amrutlal committed Sep 4, 2023
1 parent 3fc29da commit 9b6feed
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/apps/graph/generated-schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ type Block implements Node {
hash: ID!
height: BigInt!
id: ID!
parent: String!
parent: Block
parentHash: String
parent_old: String!
powhash: String!
transactions(after: String, before: String, events: [String!] = [], first: Int, last: Int): BlockTransactionsConnection!
}
Expand Down
21 changes: 20 additions & 1 deletion packages/apps/graph/src/graph/objects/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,28 @@ export default builder.prismaNode('Block', {
epoch: t.expose('epoch', { type: 'DateTime' }),
height: t.expose('height', { type: 'BigInt' }),
powhash: t.exposeString('powhash'),
parent: t.exposeString('parent'),
parent_old: t.exposeString('parent'),

// computed fields
parent: t.prismaField({
type: 'Block',
nullable: true,
resolve(query, parent, args, context, info) {
return prismaClient.block.findUnique({
where: {
hash: parent.parent,
},
});
},
}),

parentHash: t.string({
nullable: true,
resolve: (parent, args, context, info) => {
// Access the parent block's hash from the parent object
return parent.parent;
},
}),

// relations
transactions: t.prismaConnection({
Expand Down

0 comments on commit 9b6feed

Please sign in to comment.