Skip to content

Instantly share code, notes, and snippets.

@the-vampiire
Created August 8, 2018 06:25
Show Gist options
  • Select an option

  • Save the-vampiire/7bc7c1831b8a92494ac3fe144bf63b46 to your computer and use it in GitHub Desktop.

Select an option

Save the-vampiire/7bc7c1831b8a92494ac3fe144bf63b46 to your computer and use it in GitHub Desktop.
Map Attributes for reducing database server load on GraphQL resolver calls
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