I've got a requirement to move complex switches logic from UI layer to GraphQL layer. This complex switches logic is to perform a computation based on a bunch of backend configurations to determine whether a set of UI components should be shown or hidden. To show or hide a particular UI component in the set, it requires at least 3 levels deep of nested if-else branches logic. I'm currently thinking of adding the following type to the schema to solve this problem:
type MyComplexView {
componentAShown: Boolean!
componentBShown: Boolean!
# ... (gazzillion of other components here)
componentXShown: Boolean!
}
...and then I'd expect the data returned from the query would look something like:
{
"data": {
"myComplexView": {
"componentAShown": true,
"componentBShown": false,
// ... (gazzillion of other components here)
"componentXShown": true,
}
}
}
But it just doesn't feel right, and it feels like I'm abusing the GraphQL layer for doing this kind of job.
So question is, is this also a valid use case for making use of GraphQL? Is there an alternative or better way of doing it? The idea is to share the complex switches logic for all the clients (e.g. web and mobile) that are going to consume the API without re-writing/duplicating the logic again on the client-side.