Created
July 23, 2018 21:09
-
-
Save sogoiii/7f3970d8ffaa79aabc81777adfa13aa4 to your computer and use it in GitHub Desktop.
This will create the output mapper for ethereum-to-graphql
This file contains 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
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