I have a GraphQL enum like:
class MediaFilterType < Types::BaseEnum
value "TWITTER", value: :twitter
value "FACEBOOK", value: :facebook
value "YOUTUBE", value: :youtube
end
And a field that receives an array of this type or nil. Actually when we receive nil, we should pass along that we are going to use all available values in the enum:
def dashboard(media_types: nil)
if media_type.nil?
# Here is the problem below
media_types = MediaFilterType.values.values.map(&:value)
end
...
DashboardQuery.new(media_types).call
end
So I have to do this conditional sanitization for every field just like dashboard field. Not a big deal, except for the duplication. But I think this is a responsibility that should be inside the Query (there is a collaborator that can do that sanitizing inside the Query object). But I think it would be worse to extract the values from the GQL enum type inside a business object. Actually don't even know if I should be extracting these enum values anyway.
Is it good practice to extract values from the GQL type like that?
- If it is ok, there is another way to use the enum values inside a business object like a query object or a sanitizer without having them depend on the GQL enum type? Should I create an Enum with the same values in my business layer?
Appreciate any help.