Skip to content

Instantly share code, notes, and snippets.

@AlecAivazis
Last active March 7, 2019 10:25
Show Gist options
  • Save AlecAivazis/f884cd203e342bc35e476b9666667dac to your computer and use it in GitHub Desktop.
Save AlecAivazis/f884cd203e342bc35e476b9666667dac to your computer and use it in GitHub Desktop.
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