Skip to content

Commit

Permalink
Merge pull request #64 from input-output-hk/release/0.2.1
Browse files Browse the repository at this point in the history
Release/0.2.1
  • Loading branch information
rhyslbw authored Nov 1, 2019
2 parents bdc9c92 + af4681e commit 1c43625
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cardano-graphql",
"version": "0.2.0",
"version": "0.2.1",
"description": "GraphQL API for Cardano with client-consumable types generated",
"scripts": {
"codegen:external": "graphql-codegen --config ./codegen.external.yml",
Expand Down
55 changes: 54 additions & 1 deletion src/__snapshots__/integration.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,60 @@ Object {
}
`;

exports[`Integration cardano Returns the block height 1`] = `31070`;
exports[`Integration cardano Returns key information about the network 1`] = `
Object {
"data": Object {
"cardano": Object {
"blockHeight": 31070,
"currentEpoch": Object {
"number": 1,
},
"protocolConst": 2160,
"slotDuration": 20000,
"startTime": "2017-09-23T21:44:51",
},
},
"errors": undefined,
"extensions": undefined,
"http": Object {
"headers": Headers {
Symbol(map): Object {},
},
},
}
`;

exports[`Integration epochs Can return aggregated Epoch data 1`] = `
Object {
"data": Object {
"epochs_aggregate": Object {
"aggregate": Object {
"count": "2",
"max": Object {
"number": "1",
"output": "17282903106017760",
"transactionsCount": "5344",
},
"min": Object {
"output": "10378568796482912",
"transactionsCount": "33",
},
"sum": Object {
"output": "27661471902500670",
"transactionsCount": "5377",
},
},
},
},
"errors": undefined,
"extensions": undefined,
"http": Object {
"headers": Headers {
Symbol(map): Object {},
},
},
}
`;

exports[`Integration epochs Can return aggregated data 1`] = `
Object {
Expand Down
34 changes: 31 additions & 3 deletions src/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,32 @@ describe('Integration', () => {
expect(result).toMatchSnapshot()
})

it('Can return aggregated Epoch data', async () => {
const result = await client.query({
query: gql`query {
epochs_aggregate {
aggregate {
count
max {
number
output
transactionsCount
}
min {
output
transactionsCount
}
sum {
output
transactionsCount
}
}
}
}`
})
expect(result).toMatchSnapshot()
})

it('Returns blocks scoped to epoch', async () => {
const validQueryResult = await client.query({
query: gql`query {
Expand Down Expand Up @@ -276,19 +302,21 @@ describe('Integration', () => {
})

describe('cardano', () => {
it('Returns the block height', async () => {
it('Returns key information about the network', async () => {
const result = await client.query({
query: gql`query {
cardano {
blockHeight
currentEpoch {
number
}
protocolConst
slotDuration
startTime
}
}`
})
expect(result.data.cardano.blockHeight).toBe(31070)
expect(result.data.cardano.blockHeight).toMatchSnapshot()
expect(result).toMatchSnapshot()
})
})

Expand Down
28 changes: 25 additions & 3 deletions src/resolvers/hasura_resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,37 @@ export const hasuraResolvers: Resolvers = {
schema: context.hasura
})
},
cardano: async (_root, args, context, info) => {
return (await delegateToSchema({
epochs_aggregate: (_root, args, context, info) => {
return delegateToSchema({
args,
context,
fieldName: 'Epoch_aggregate',
info,
operation: 'query',
schema: context.hasura
})
},
cardano: async (_root, _args, context, info) => {
// These two queries are very lightweight, just selecting single rows,
// Could optimise, but there's little performance gain
const cardanoResult = await delegateToSchema({
context,
fieldName: 'Cardano',
info,
operation: 'query',
schema: context.hasura
}))[0]
})
const metaResult = await delegateToSchema({
context,
fieldName: 'Meta',
info,
operation: 'query',
schema: context.hasura
})
return {
...cardanoResult ? cardanoResult[0] : undefined,
...metaResult ? metaResult[0] : undefined
}
},
transactions: (_root, args, context, info) => {
return delegateToSchema({
Expand Down
36 changes: 36 additions & 0 deletions src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ type Query {
offset: Int
where: Epoch_bool_exp
): [Epoch]!
epochs_aggregate (
limit: Int
order_by: [Epoch_order_by!]
offset: Int
where: Epoch_bool_exp
): Epoch_aggregate!
cardano: Cardano
transactions (
limit: Int
Expand All @@ -39,6 +45,9 @@ type Query {
type Cardano {
blockHeight: Int!
currentEpoch: Epoch!
protocolConst: Int!
slotDuration: Int!
startTime: DateTime!
}

type Transaction {
Expand Down Expand Up @@ -248,6 +257,33 @@ input Epoch_order_by {
fees: order_by
}

type Epoch_aggregate {
aggregate: Epoch_aggregate_fields!
}

type Epoch_aggregate_fields {
count: String!
max: Epoch_max_fields!
min: Epoch_min_fields!
sum: Epoch_sum_fields!
}

type Epoch_max_fields {
number: String!
output: String!
transactionsCount: String!
}

type Epoch_min_fields {
output: String!
transactionsCount: String!
}

type Epoch_sum_fields {
output: String!
transactionsCount: String!
}

input Utxo_bool_exp {
address: text_comparison_exp
}
Expand Down
2 changes: 1 addition & 1 deletion test/postgres/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM postgres:11.5-alpine
COPY test/postgres/init /docker-entrypoint-initdb.d
ENV POSTGRES_USER nix
ENV POSTGRES_USER postgres
ENV POSTGRES_DB cexplorer

0 comments on commit 1c43625

Please sign in to comment.