Skip to content

Commit

Permalink
feature: tokenMints and tokenMints_aggregate queries
Browse files Browse the repository at this point in the history
  • Loading branch information
rhyslbw committed Apr 19, 2021
1 parent 7616a49 commit f803b94
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/api-cardano-db-hasura/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ type Query {
offset: Int
where: StakeRegistration_bool_exp
): StakeRegistration_aggregate
tokenMints (
limit: Int
order_by: [TokenMint_order_by!]
offset: Int
where: TokenMint_bool_exp
): [TokenMint]!
tokenMints_aggregate (
limit: Int
order_by: [TokenMint_order_by!]
offset: Int
where: TokenMint_bool_exp
): TokenMint_aggregate!
transactions (
limit: Int
order_by: [Transaction_order_by!]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
query tokenMints (
$limit: Int
$offset: Int
$where: TokenMint_bool_exp
) {
tokenMints (
limit: $limit
offset: $offset
where: $where
) {
asset {
assetId
assetName
description
fingerprint
logo
name
policyId
ticker
url
}
quantity
transaction {
hash
}
}
tokenMints_aggregate {
aggregate {
count
sum {
quantity
}
}
}
}
20 changes: 20 additions & 0 deletions packages/api-cardano-db-hasura/src/executableSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,26 @@ export async function buildSchema (
schema: hasuraClient.schema
})
},
tokenMints: (_root, args, context, info) => {
return delegateToSchema({
args,
context,
fieldName: 'tokenMints',
info,
operation: 'query',
schema: hasuraClient.schema
})
},
tokenMints_aggregate: (_root, args, context, info) => {
return delegateToSchema({
args,
context,
fieldName: 'tokenMints_aggregate',
info,
operation: 'query',
schema: hasuraClient.schema
})
},
utxos: (_root, args, context, info) => {
return delegateToSchema({
args,
Expand Down
2 changes: 1 addition & 1 deletion packages/api-cardano-db-hasura/test/assets.query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('assets', () => {
fingerprint: { _eq: 'asset12h3p5l3nd5y26lr22am7y7ga3vxghkhf57zkhd' },
tokenMints: { transaction: { includedAt: { _gt: '2017-09-23T21:44:51Z' } } }
}]
},
}
}
})
const { assets } = result.data
Expand Down
53 changes: 53 additions & 0 deletions packages/api-cardano-db-hasura/test/tokenMints.query.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* eslint-disable camelcase */
import path from 'path'

import { DocumentNode } from 'graphql'
import util from '@cardano-graphql/util'
import { TestClient } from '@cardano-graphql/util-dev'
import { testClient } from './util'

function loadQueryNode (name: string): Promise<DocumentNode> {
return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries', 'token_mints'), name)
}

describe('tokenMints', () => {
let client: TestClient
beforeAll(async () => {
client = await testClient.mainnet()
})

it('can return information on token minting and burning', async () => {
const result = await client.query({
query: await loadQueryNode('tokenMints'),
variables: {
limit: 2
}
})
const { tokenMints_aggregate, tokenMints } = result.data
const { aggregate } = tokenMints_aggregate
expect(aggregate.count).toBeDefined()
expect(tokenMints.length).toBeGreaterThan(0)
expect(parseInt(tokenMints_aggregate.aggregate.count)).toBeGreaterThan(0)
expect(tokenMints[0].asset.fingerprint.slice(0, 5)).toBe('asset')
})

it('can return information on assets by fingerprint', async () => {
const result = await client.query({
query: await loadQueryNode('tokenMints'),
variables: {
where: {
asset: { fingerprint: { _eq: 'asset12h3p5l3nd5y26lr22am7y7ga3vxghkhf57zkhd' } }
},
orderBy: {
transaction: { includedAt: 'desc' }
}
}
})
const { tokenMints } = result.data
expect(tokenMints[0].quantity).toBeDefined()
expect(tokenMints[0].transaction.hash).toBeDefined()
expect(tokenMints[0].asset.assetId).toBeDefined()
expect(tokenMints[0].asset.fingerprint).toBeDefined()
expect(tokenMints[0].asset.policyId).toBeDefined()
})
})

0 comments on commit f803b94

Please sign in to comment.