Replies: 2 comments 3 replies
-
Hey, great question. As you noticed, you can't have two types with the same name. I think the best way would be to implement def self.coerce_input(value, context)
if valid_uuid?(value) || valid_base54_thingy?(value)
value
else
raise GraphQL::ExecutionError, "Invalid ID: #{value.inspect}"
end
end That way, in GraphQL, it looks like a single type ( Now that I write it up, it strikes me that maybe you want some fields to require UUIDs while other fields require base54 IDs. If that's the case, you'd still use a single ID, but you'd validate it on an argument-by-argument basis. A couple options there:
How does all that sound? |
Beta Was this translation helpful? Give feedback.
-
So what you are suggesting is we do something like this?
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
One of the most used scalars is ID, it's great! However our application has 2 types of ids. Some of them are UUID based, and others are some weird base54 thingy.
Now, we want to start validating these IDs (especially on input), but I don't want this to be reflected in the input (over time some of the UUID based IDS become the base 54 ones) and is more of an internal issue then it is an external one.
So I was thinking of leaving the uuid based ones to
GraphQL::Types::ID
and extend itscoerce_input
method to deal with the validation. And I would create a new Scalar with the samegraphql_name
for the base54 based ids.Not unsurprising I got a
GraphQL::Schema::DuplicateNamesError
and there seems no way around this...I think the above case is a valid example where I can have 2 internal implementations for the same external type. (I really don't want to change the external types). Is there an other way to achieve what I want to do? Or is this an opportunity for a new feature?
Beta Was this translation helpful? Give feedback.
All reactions