cardano-graphql
cardano-graphql
Please visit cardano-graphql release notes on GitHub here for more information on new features, dependencies, bug fixes, breaking changes, pre-releases, plus more.
What is cardano-graphql?
cardano-graphql is a Cardano query language for API and a runtime for fulfilling queries with existing data extracted from the cardano-db-sync PostgreSQL database. It provides a complete and understandable description of this data and gives clients the power to request the necessary information. This, in turn, makes it easier to evolve client API’s overtime and enables powerful developer tools.
cardano-graphql uses an extensible framework to retrieve transactions, addresses, and time periods (epochs and slots) from the cardano-db-sync component. For more information on these components please see the Adrestia GitHub page here.
Building and Running
cardano-graphql and cardano-db-sync have been built and tested on Linux and Docker images are available on DockerHub. The recommended method to build cardano-graphql is docker-compose and a sample docker-compose file is provided here.
https://github.com/input-output-hk/cardano-graphql#build-and-run-via-docker-compose
The cardano-graphql and cardano-db-sync are designed to work with a locally running cardano-node. For instructions on how to build and deploy cardano-graphql please see the cardano-graphql README file
Accessing cardano-graphql playground
Once cardano-graphql is up and running, the graphql playground should accessible at the
http://localhost:3100/graphql
Accessing the playground at this location confirms everything is running correctly.
Building cardano-graphql queries
cardano-graphql offers an independent API fully customizable to any requirement or need. To start constructing cardano-graphql queries using playground search the doc pages on the right for the available attribute upon which you can build the query like below:
curl cardano-graphql API
After successfully building and testing the query via cardano-graphql playground, it's possible to copy the corresponding curl request via the COPY CURL button at the top right-hand corner of the playground browser like below:
Once the corresponding request has been copied it's possible to run the curl command via a command line like below:
curl 'http://localhost:3100/graphql' -H 'Accept-Encoding: gzip, deflate, br' -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Connection: keep-alive' -H 'DNT: 1' -H 'Origin: http://localhost:3100' --data-binary '{"query":"query getBlockTxs($hash: Hash32Hex!) {\n blocks (limit: 1, where: { hash: { _eq: $hash } }){\n transactions {\n hash # ctbId\n includedAt # ctbTimeIssued\n fee # ctbFees\n inputs {\n # ctbInputs\n address # ctaAddress\n value # ctaAmount\n sourceTxHash # ctaTxHash\n sourceTxIndex # ctaTxIndex\n }\n inputs_aggregate {\n aggregate {\n sum {\n value # ctbInputSum\n }\n }\n }\n outputs { # ctbOutputs\n address # ctaAddress\n index # ctaTxIndex\n value # ctaAmoun\n transaction {\n hash # ctaTxHash \n mint { \n asset {\n assetId\n assetName \n policyId} \n quantity}\n }\n tokens {\n asset {\n assetId \n assetName \n policyId}\n quantity}\n }\n outputs_aggregate {\n aggregate {\n sum {\n value # ctbOutputSum\n }\n }\n }\n }\n}\n}","variables":{"hash":"a9c1d60da42f43ed40c28ee2428e037c014bffa111cfc06897feefa0d9025bd2"}}' --compressed
Related documentation
Cardano GraphQL API documentation
cardano-rest migration guide (sample GQL queries)