Skip to content

Instantly share code, notes, and snippets.

@sogoiii
Created July 23, 2018 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sogoiii/7f3970d8ffaa79aabc81777adfa13aa4 to your computer and use it in GitHub Desktop.
Save sogoiii/7f3970d8ffaa79aabc81777adfa13aa4 to your computer and use it in GitHub Desktop.
This will create the output mapper for ethereum-to-graphql
const genOutputFn = (outputTypesDef) => {
return (result) => {
const resultsIsArr = Array.isArray(result)
const outputTypesDefIsArray = Array.isArray(outputTypesDef)
const combined = zipOutputWithResults(resultsIsArr, outputTypesDefIsArray, result, outputTypesDef)
return combined.reduce((out, current) => {
let { key, name, result } = current
if (key === 'value') {
if (Array.isArray(result)) {
out[name] = result.map(item => {
return parseValueResult(item)
})
} else {
out[name] = parseValueResult(result)
}
} else if (key === 'bytes') {
if (Array.isArray(result)) {
out[name] = result.map(item => {
return parseBytesResult(item)
})
} else {
out[name] = parseBytesResult(result)
}
} else {
out[name] = result
}
return out
}, {})
}
}
// Pupose of this method is to create the function that will receive data from Ethereum and return to graphQL for further processing
const genOutputFnMapper = ({ queryConverter }) => {
return queryConverter
.map(item => {
return { fnName: item.name, outputMapper: genOutputFn(item.types) }
})
.reduce((out, cur) => {
out[cur.fnName] = cur.outputMapper
return out
}, {})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment