I have a question, how do I do data denormalisatio...
# orm-help
m
I have a question, how do I do data denormalisation / transformation / whatever you want to call it. I get the data via graphql/apollo from graphcool to my react component but than I have to transform it. Lets say I have products and they have a condition good,poor,avg (in the graphcool database) but in my component I want to show "Very good", "Not functioning", "Average". Usually I'd transform them in the backend and send to the client via an API only what I need. I could transform the data in the
componentDidMount()
method but as my application grows, thats very shit for scaling to do everything on the client since the bundle grows and grows. So my question: What is the best way to encounter this problem? Any suggestion is a good suggestion, I'm still at a stage were I can easily rewrite a bunch of code. Thank you
l
I'd just make a translation object and call a function at render time, e.g.
Copy code
function translateCondition(selectedCondition) {
    const conditions = {
           good: "Good", great: "Totally Awesome" ...
    }
   return conditions[selectedCondition] || `translation not found`
}

...
const Component = ({ selectedCondition }) => (
   <div>{translateCondition(selectedCondition)}</div>
)  // "Totally Awesome"
Normally these are ok to be hard coded because they infrequently change and are part of your UI, but you could always store them on the server and make a GraphQL query for the translation object.