Ethereum ABI to GraphQL Scheme
This will consume an ABI object created when deploying a Solidity/Viper/Serpent Smart contract, and return a graphql schema and resolver. This object can be plugged into a the graphql server of your choice.
Setup:
Install the package with npm or yarn.
npm install ethereum-to-graphql
yarn add ethereum-to-graphql
Your server will have to read an abi file and pass it through this package. We return an object that you pass into your graqhQL server.
const express = require('express');
const graphqlHTTP = require('express-graphql');
const graphql = require('graphql')
const app = express();
const MetaCoinArtifact = require('./build/contracts/Metacoin')
const url = 'http://localhost:8545'
const { genGraphQlProperties } = require('ethereum-to-graphql')
const { schema, rootValue } = genGraphQlProperties({ artifacts: [MetaCoinArtifact], provider: { url }, graphql })
app.use('/graphql', graphqlHTTP({
schema: schema,
rootValue: rootValue,
graphiql: true
}));
app.listen(4000);
Testing
To run tests, you will need to have truffle and testrpc installed globally.
- Terminal Window 1:
cd <this project>
- Terminal Window 1:
testrpc
- Terminal Window 2:
cd <this project>
- Terminal Window 2:
truffle migrate
- Terminal Window 2:
npm test
Gotcha
FYI : use
"web3": "0.19.0"
to not breaking thing
testrpc
yarn install
yarn build
yarn deploy
yarn test
yarn server
yarn client-react
open http://localhost:4000/graphql