How to implement a type definition with a field that could be one of several scalar types? #834
Unanswered
gabrielalack
asked this question in
Q&A
Replies: 1 comment
-
GraphQL itself supports unions, see https://graphql.org/learn/schema/#union-types However it's only supported on "object types", you can't have unions for If you don't care about the GraphQL type-safety system, you can always just make it return string and encode the value on the server with json and decode it on the client. But besides that, this isn't possible (per the spec; not a limitation of this library iself). |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a table that is a set of custom fields that people can configure, with an immutable
type
field that defines the data type of the value the field contains. The eloquent model has a couple of getters will return the correct field type based on the type specified as what the field is supposed to be, basically, string, float, carbon date, or boolean.We have a
default_value
field on thecustom_field
table. We map them it to related records via a BelongsToMany relationship with a pivot table that has a pivot fieldevent_value
that relates directly to that data (in our case, concert/events)Our Eloquent Model:
As you can see, if my model is defined as a
date
type, it will give me a Carbon object when I access$record->default_value
. If the model has a type of 'toggle' it will give me a boolean value, etc.The problem comes in when I need to define the type for GraphQL, which doesn't seem to like mixed types on a single field definition. How can I configure this?
Beta Was this translation helpful? Give feedback.
All reactions