-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: tokenMints and tokenMints_aggregate queries
- Loading branch information
Showing
5 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/api-cardano-db-hasura/src/example_queries/token_mints/tokenMints.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
packages/api-cardano-db-hasura/test/tokenMints.query.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) |