Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@kadena/graph] Feat: Update prisma schema to follow naming convention #998

Merged
merged 19 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
119f5e0
removed event parameters and added paramtext; adjusted the client pag…
nil-amrutlal Oct 4, 2023
f5aa5c5
fix fetching of events and eventpage
nil-amrutlal Oct 5, 2023
fa782aa
change while statement on block so that subscription stops even if no…
nil-amrutlal Oct 5, 2023
96363cb
Merge remote-tracking branch 'origin/main' into fix/graph/event-param…
nil-amrutlal Oct 5, 2023
004688a
add empty changeset
nil-amrutlal Oct 5, 2023
594f0f1
lint fix
nil-amrutlal Oct 5, 2023
367962e
removed commentary
nil-amrutlal Oct 5, 2023
624622a
fix lint
nil-amrutlal Oct 5, 2023
7fd58f1
Merge branch 'main' into fix/graph/event-parameters-formatting
nil-amrutlal Oct 5, 2023
55593dc
applied naming convention on prisma fields and changed graphql querie…
nil-amrutlal Oct 5, 2023
9bc39f5
add empty changeset
nil-amrutlal Oct 5, 2023
7e0547d
Merge commit '44b2c3910e6310d2a5f1f5307b277c7bcea6e739' into graph/fe…
nil-amrutlal Oct 5, 2023
18b6780
apply naming convention to powhash field
nil-amrutlal Oct 6, 2023
0acd428
change graphql field accordingly
nil-amrutlal Oct 6, 2023
b552ffd
changes in client to accomodate graphql schema changes
nil-amrutlal Oct 6, 2023
70de13d
Merge remote-tracking branch 'origin/main' into graph/feat/prisma-sch…
nil-amrutlal Oct 6, 2023
ebecbe8
Merge branch 'graph/feat/prisma-schema-naming-convention' into fix/gr…
nil-amrutlal Oct 6, 2023
37ea045
changed paramText to new naming convention in client
nil-amrutlal Oct 6, 2023
01066a9
Merge pull request #989 from kadena-community/fix/graph/event-paramet…
nil-amrutlal Oct 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/lucky-flies-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
1 change: 0 additions & 1 deletion packages/apps/graph/generated-schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type Block implements Node {
id: ID!
parent: Block
parentHash: String
parent_old: String!
powhash: String!
transactions(after: String, before: String, events: [String!] = [], first: Int, last: Int): BlockTransactionsConnection!
}
Expand Down
192 changes: 96 additions & 96 deletions packages/apps/graph/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -12,124 +12,124 @@ datasource db {
}

model Block {
chainid BigInt
creationtime DateTime @db.Timestamptz(6)
epoch DateTime @db.Timestamptz(6)
flags Decimal @db.Decimal(20, 0)
hash String @id @db.VarChar
height BigInt
miner String @db.VarChar
nonce Decimal @db.Decimal(20, 0)
parent String @db.VarChar
payload String @db.VarChar
powhash String @db.VarChar
predicate String @db.VarChar
target Decimal @db.Decimal(80, 0)
weight Decimal @db.Decimal(80, 0)
id Int @unique(map: "blocks_id_uniq") @default(autoincrement())
events Event[]
minerkeys Minerkey[]
transactions Transaction[]
transfers Transfer[]

@@index([height(sort: Desc), chainid])
chainId BigInt @map("chainid")
creationTime DateTime @db.Timestamptz(6) @map("creationtime")
epoch DateTime @db.Timestamptz(6)
flags Decimal @db.Decimal(20, 0)
hash String @id @db.VarChar
height BigInt
minerAccount String @db.VarChar @map("miner")
nonce Decimal @db.Decimal(20, 0)
parentBlockHash String @db.VarChar @map("parent")
payload String @db.VarChar
powHash String @db.VarChar @map("powhash")
predicate String @db.VarChar
target Decimal @db.Decimal(80, 0)
weight Decimal @db.Decimal(80, 0)
id Int @unique(map: "blocks_id_uniq") @default(autoincrement())
events Event[]
minerKeys Minerkey[]
transactions Transaction[]
transfers Transfer[]

@@index([height(sort: Desc), chainId])
@@map("blocks")
}

model Event {
blockhash String @db.VarChar @map("block")
chainid BigInt
height BigInt
idx BigInt
module String @db.VarChar
modulehash String @db.VarChar
name String @db.VarChar
params Json
paramtext String @db.VarChar
qualname String @db.VarChar
requestkey String @db.VarChar
id Int @unique(map: "events_id_uniq") @default(autoincrement())
transaction Transaction? @relation(fields: [blockhash, requestkey], references: [blockhash, requestkey])
block Block @relation(fields: [blockhash], references: [hash], onDelete: NoAction, onUpdate: NoAction)

@@id([blockhash, idx, requestkey])
@@index([height(sort: Desc), chainid, idx], map: "events_height_chainid_idx")
@@index([requestkey])
blockHash String @db.VarChar @map("block")
chainId BigInt @map("chainid")
height BigInt
orderIndex BigInt @map("idx")
moduleName String @db.VarChar @map("module")
moduleHash String @db.VarChar @map("modulehash")
name String @db.VarChar
parameters Json @map("params")
parameterText String @db.VarChar @map("paramtext")
qualifiedName String @db.VarChar @map("qualname")
requestKey String @db.VarChar @map("requestkey")
id Int @unique(map: "events_id_uniq") @default(autoincrement())
transaction Transaction? @relation(fields: [blockHash, requestKey], references: [blockHash, requestKey])
block Block @relation(fields: [blockHash], references: [hash], onDelete: NoAction, onUpdate: NoAction)

@@id([blockHash, orderIndex, requestKey])
@@index([height(sort: Desc), chainId, orderIndex], map: "events_height_chainid_orderIndex")
@@index([requestKey])
@@map("events")
}

model Minerkey {
block String @db.VarChar
key String @db.VarChar
blocks Block @relation(fields: [block], references: [hash], onDelete: NoAction, onUpdate: NoAction)
blockHash String @db.VarChar @map("block")
key String @db.VarChar
blocks Block @relation(fields: [blockHash], references: [hash], onDelete: NoAction, onUpdate: NoAction)

@@id([block, key])
@@id([blockHash, key])
@@map("minerkeys")
}

model Signer {
addr String? @db.VarChar
caps Json
idx Int
pubkey String @db.VarChar
requestkey String @db.VarChar
scheme String? @db.VarChar
sig String @db.VarChar

@@id([idx, requestkey])
address String? @db.VarChar @map("addr")
capabilities Json @map("caps")
orderIndex Int @map("idx")
publicKey String @db.VarChar @map("pubkey")
requestKey String @db.VarChar @map("requestkey")
scheme String? @db.VarChar
signature String @db.VarChar @map("sig")

@@id([orderIndex, requestKey])
@@map("signers")
}

model Transaction {
badresult Json?
blockhash String @db.VarChar @map("block")
chainid BigInt
code String? @db.VarChar
continuation Json?
creationtime DateTime @db.Timestamptz(6)
data Json?
gas BigInt
gaslimit BigInt
gasprice Float
goodresult Json?
height BigInt
logs String? @db.VarChar
metadata Json?
nonce String @db.VarChar
num_events BigInt?
pactid String? @db.VarChar
proof String? @db.VarChar
requestkey String @db.VarChar
rollback Boolean?
sender String @db.VarChar
step BigInt?
ttl BigInt
txid BigInt?
events Event[]
block Block @relation(fields: [blockhash], references: [hash], onDelete: NoAction, onUpdate: NoAction)

@@id([blockhash, requestkey], map: "transaction_pkey")
badResult Json? @map("badresult")
blockHash String @map("block")
chainId BigInt @map("chainid")
code String? @db.VarChar
continuation Json?
creationTime DateTime @db.Timestamptz(6) @map("creationtime")
data Json?
gas BigInt
gasLimit BigInt @map("gaslimit")
gasPrice Float @map("gasprice")
goodResult Json? @map("goodresult")
height BigInt
logs String? @db.VarChar
metadata Json?
nonce String @db.VarChar
eventCount BigInt? @map("num_events")
pactId String? @db.VarChar @map("pactid")
proof String? @db.VarChar
requestKey String @db.VarChar @map("requestkey")
rollback Boolean?
sender String @db.VarChar
step BigInt?
ttl BigInt
transactionId BigInt? @map("txid")
events Event[]
block Block @relation(fields: [blockHash], references: [hash], onDelete: NoAction, onUpdate: NoAction)

@@id([blockHash, requestKey], map: "transaction_pkey")
@@index([height])
@@index([requestkey])
@@index([requestKey])
@@map("transactions")
}

model Transfer {
amount Decimal @db.Decimal
block String @db.VarChar
chainid BigInt
from_acct String @db.VarChar
height BigInt
idx BigInt
modulehash String @db.VarChar
modulename String @db.VarChar
requestkey String @db.VarChar
to_acct String @db.VarChar
blocks Block @relation(fields: [block], references: [hash], onDelete: NoAction, onUpdate: NoAction)

@@id([block, chainid, idx, modulehash, requestkey])
@@index([from_acct, height(sort: Desc), idx], map: "transfers_from_acct_height_idx")
@@index([to_acct, height(sort: Desc), idx])
amount Decimal @db.Decimal
block String @db.VarChar
chainId BigInt @map("chainid")
senderAccount String @db.VarChar @map("from_acct")
height BigInt
orderIndex BigInt @map("idx")
moduleHash String @db.VarChar @map("modulehash")
moduleName String @db.VarChar @map("modulename")
requestKey String @db.VarChar @map("requestkey")
receiverAccount String @db.VarChar @map("to_acct")
blocks Block @relation(fields: [block], references: [hash], onDelete: NoAction, onUpdate: NoAction)

@@id([block, chainId, orderIndex, moduleHash, requestKey])
@@index([senderAccount, height(sort: Desc), orderIndex], map: "transfers_senderAccount_height_orderIndex")
@@index([receiverAccount, height(sort: Desc), orderIndex])
@@map("transfers")
}

Expand Down
2 changes: 1 addition & 1 deletion packages/apps/graph/src/graph/Query/blocksFromHeight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ builder.queryField('blocksFromHeight', (t) => {
},
},
{
chainid: {
chainId: {
in: chainIds as number[],
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/graph/src/graph/Subscription/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async function getLastEvent(eventName: string, id?: number): Promise<Event[]> {
const foundEvents = await prismaClient.event.findMany({
...extendedFilter,
where: {
qualname: eventName,
qualifiedName: eventName,
transaction: {
NOT: [],
},
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/graph/src/graph/Subscription/newBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async function getLastBlocks(

const foundblocks = await prismaClient.block.findMany({
...extendedFilter,
where: { ...extendedFilter.where, chainid: { in: chainIds } },
where: { ...extendedFilter.where, chainId: { in: chainIds } },
});

log("found '%s' blocks", foundblocks.length);
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/graph/src/graph/Subscription/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function* iteratorFn(
while (!context.req.socket.destroyed) {
const transaction = await prismaClient.transaction.findFirst({
where: {
requestkey: requestKey,
requestKey: requestKey,
},
});

Expand Down
21 changes: 10 additions & 11 deletions packages/apps/graph/src/graph/objects/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ export default builder.prismaNode('Block', {
fields: (t) => ({
// database fields
hash: t.exposeID('hash'),
chainid: t.expose('chainid', { type: 'BigInt' }),
MRVDH marked this conversation as resolved.
Show resolved Hide resolved
creationtime: t.expose('creationtime', { type: 'DateTime' }),
chainid: t.expose('chainId', { type: 'BigInt' }),
creationtime: t.expose('creationTime', { type: 'DateTime' }),
epoch: t.expose('epoch', { type: 'DateTime' }),
height: t.expose('height', { type: 'BigInt' }),
powhash: t.exposeString('powhash'),
parent_old: t.exposeString('parent'),
powhash: t.exposeString('powHash'),

// computed fields
parent: t.prismaField({
Expand All @@ -24,7 +23,7 @@ export default builder.prismaNode('Block', {
resolve(query, parent, args, context, info) {
return prismaClient.block.findUnique({
where: {
hash: parent.parent,
hash: parent.parentBlockHash,
},
});
},
Expand All @@ -34,7 +33,7 @@ export default builder.prismaNode('Block', {
nullable: true,
resolve: (parent, args, context, info) => {
// Access the parent block's hash from the parent object
return parent.parent;
return parent.parentBlockHash;
},
}),

Expand All @@ -44,12 +43,12 @@ export default builder.prismaNode('Block', {
events: t.arg.stringList({ required: false, defaultValue: [] }),
},
type: 'Transaction',
cursor: 'blockhash_requestkey',
cursor: 'blockHash_requestKey',
async totalCount(parent, { events }, context, info) {
return prismaClient.transaction.count({
where: {
blockhash: parent.hash,
requestkey: {
blockHash: parent.hash,
requestKey: {
in: await getTransactionsRequestkeyByEvent(events || [], parent),
},
},
Expand All @@ -59,8 +58,8 @@ export default builder.prismaNode('Block', {
return prismaClient.transaction.findMany({
...query,
where: {
blockhash: parent.hash,
requestkey: {
blockHash: parent.hash,
requestKey: {
in: await getTransactionsRequestkeyByEvent(events || [], parent),
},
},
Expand Down
22 changes: 11 additions & 11 deletions packages/apps/graph/src/graph/objects/Event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ import { prismaClient } from '../../db/prismaClient';
import { builder } from '../builder';

export default builder.prismaNode('Event', {
id: { field: 'blockhash_idx_requestkey' },
id: { field: 'blockHash_orderIndex_requestKey' },
fields: (t) => ({
// database fields
chainId: t.expose('chainid', { type: 'BigInt' }),
chainId: t.expose('chainId', { type: 'BigInt' }),
height: t.expose('height', { type: 'BigInt' }),
index: t.expose('idx', { type: 'BigInt' }),
module: t.exposeString('module'),
index: t.expose('orderIndex', { type: 'BigInt' }),
MRVDH marked this conversation as resolved.
Show resolved Hide resolved
module: t.exposeString('moduleName'),
name: t.exposeString('name'),
qualName: t.exposeString('qualname'),
requestKey: t.exposeString('requestkey'),
qualName: t.exposeString('qualifiedName'),
MRVDH marked this conversation as resolved.
Show resolved Hide resolved
requestKey: t.exposeString('requestKey'),

// computed fields
eventParameters: t.field({
type: ['String'],
resolve(parent) {
return JSON.parse(parent.paramtext);
return JSON.parse(parent.parameterText);
},
}),

Expand All @@ -28,9 +28,9 @@ export default builder.prismaNode('Event', {
resolve(query, parent, args, context, info) {
return prismaClient.transaction.findUnique({
where: {
blockhash_requestkey: {
blockhash: parent.blockhash,
requestkey: parent.requestkey,
blockHash_requestKey: {
blockHash: parent.blockHash,
requestKey: parent.requestKey,
},
},
});
Expand All @@ -44,7 +44,7 @@ export default builder.prismaNode('Event', {
resolve(query, parent, args, context, info) {
return prismaClient.block.findUniqueOrThrow({
where: {
hash: parent.blockhash,
hash: parent.blockHash,
},
});
},
Expand Down
Loading