diff --git a/package-lock.json b/package-lock.json index 6999726b..3d637d24 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "cardano-graphql", - "version": "0.1.6", + "version": "0.2.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index a949cc36..897e641e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/__snapshots__/integration.spec.ts.snap b/src/__snapshots__/integration.spec.ts.snap index ece0ffb1..ef545c59 100644 --- a/src/__snapshots__/integration.spec.ts.snap +++ b/src/__snapshots__/integration.spec.ts.snap @@ -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 { diff --git a/src/integration.spec.ts b/src/integration.spec.ts index e2cb037d..5519bfee 100644 --- a/src/integration.spec.ts +++ b/src/integration.spec.ts @@ -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 { @@ -276,7 +302,7 @@ 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 { @@ -284,11 +310,13 @@ describe('Integration', () => { currentEpoch { number } + protocolConst + slotDuration + startTime } }` }) - expect(result.data.cardano.blockHeight).toBe(31070) - expect(result.data.cardano.blockHeight).toMatchSnapshot() + expect(result).toMatchSnapshot() }) }) diff --git a/src/resolvers/hasura_resolvers.ts b/src/resolvers/hasura_resolvers.ts index 4ab922bf..3082ea6b 100644 --- a/src/resolvers/hasura_resolvers.ts +++ b/src/resolvers/hasura_resolvers.ts @@ -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({ diff --git a/src/schema.graphql b/src/schema.graphql index bf6fcb95..451c2afd 100644 --- a/src/schema.graphql +++ b/src/schema.graphql @@ -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 @@ -39,6 +45,9 @@ type Query { type Cardano { blockHeight: Int! currentEpoch: Epoch! + protocolConst: Int! + slotDuration: Int! + startTime: DateTime! } type Transaction { @@ -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 } diff --git a/test/postgres/Dockerfile b/test/postgres/Dockerfile index 775e6cc5..860c3ed3 100644 --- a/test/postgres/Dockerfile +++ b/test/postgres/Dockerfile @@ -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 \ No newline at end of file