Created
August 8, 2018 06:25
-
-
Save the-vampiire/7bc7c1831b8a92494ac3fe144bf63b46 to your computer and use it in GitHub Desktop.
Map Attributes for reducing database server load on GraphQL resolver calls
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
| const mapAttributes = (model, { fieldNodes }) => { | |
| const columns = new Set(Object.keys(model.rawAttributes)); // to prevent column doesnt exist error | |
| const rawAttributes = fieldNodes[0].selectionSet.selections.map(({ name: { value } }) => value); | |
| return rawAttributes.filter(attribute => columns.has(attribute)); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment