mwickett
09/13/2017, 6:04 PM'use latest'
const fromEvent = require('graphcool-lib').fromEvent
module.exports = function(event) {
const graphcool = fromEvent(event)
const api = graphcool.api('simple/v1')
function getPrices() {
return api
.request(
`
query {
allPricings {
type
price
}
}
`
)
.then(pricingQueryResult => {
console.log(pricingQueryResult)
const filteredEntries = pricingQueryResult.allPricings.filter(
price => price.type === event.data.type
)
const applicableEntry = filteredEntries.length
? filteredEntries[0]
: false
console.log(applicableEntry.price)
return applicableEntry.price
})
.catch(error => {
return { error: error }
})
}
return getPrices().then((price) => {
const dataResponse = Object.assign({}, event.data, { priceBase: price })
return { data: dataResponse }
})
}