-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Requiring one of 2 Arguments to be required #2267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This sounds like a good use case input unions in GraphQL to support schema level enforcement of this contract. See graphql/graphql-spec#395 for more on that. In the meantime the best you can do is a runtime validation check: field :car, Types::CarType, null: false do
argument :id, ID, required: false
argument :external_id, ID, required: false
end
def car(id: :unspecified, external_id: :unspecified)
if (id == :unspecified && external_id == :unspecified) || (id != :unspecified && external_id != :unspecified)
raise GraphQL::ExecutionError.new('Must specify exactly one of id or externalId')
end
# ...
end |
ok, that is what I fell back to as well. |
Yep, best bet now is runtime, as shown above. |
@RobsonKing oneOf is now a thing: #4184 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have a field that I want to filter in one of two ways.
Is there anyway to indicate that one of the two values must be required, but not both?
I tried overriding GraphQL::Schema::Argument, but it doesn't seem like 'context' is available where 'required' is used.
The text was updated successfully, but these errors were encountered: