Last active
March 7, 2019 10:25
-
-
Save AlecAivazis/f884cd203e342bc35e476b9666667dac to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { makeExecutableSchema } from 'graphql-tools' | |
import { HubABI, AuctionABI, web3 } from '../contracts' | |
const schema = ... | |
const resolvers = { | |
Auction: { | |
// auction is an instance of the Auction contract wrapper | |
itemName: auction => auction.methods.itemName().call(), | |
}, | |
Query: { | |
allAuctions: async () => { | |
// create a reference to the hub contract we created earlier | |
const hub = new web3.eth.Contract(HubABI, 'hub address from before') | |
// build the list of auctions | |
const auctions = [] | |
for (let i = 0; i < await hub.methods.auctionCount().call(); i++) { | |
auctions.push( | |
new web3.eth.Contract( | |
AuctionABI, | |
await hub.methods.auctions(i).call() | |
) | |
) | |
} | |
return auctions | |
} | |
}, | |
} | |
export default makeExecutableSchema({ | |
typeDefs: schema, | |
resolvers, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment