-
Notifications
You must be signed in to change notification settings - Fork 36
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
Add ability to customize raise_user_error_list method #262
Comments
Thank you for your report, @vitaliiorlov! We'll take a look into this shortly. As usual, you are welcome to propose a change if you had a particular implementation in place before we get a chance to look into this :) as long as it's generic and users can opt-in to this new behavior rather than having a breaking change |
@mcelicalderon thanks for your reply. Currently, I don't have any implementation of this. If I will, I will create a PR. |
Taking a quick look, I think we should provide a way for users to specify a base mutation from which all mutation in this gem will inherit from. That way you could override the methods that raise errors in that base mutation class that you provide. This will also allow other type of customizations like setting argument classes and other things you can do at the mutation level |
@vitaliiorlov are you mounting this gem in your existing schema or are you using the separate route approach? |
@mcelicalderon sounds good. But it won't solve my problem at all because you are already passing
I mount it in the existing schema. |
That makes sense. We can do that too |
@vitaliiorlov I have opened #263 which I think is enough to accomplish what you are trying to do, but let me know if it doesn't. With that simple change, you can write your own mutation that implements a different
Define a custom mutation with your custom method definition # app/graphql/mutations/custom_register.rb
module Mutation
class CustomRegister < GraphqlDevise::Mutations::Register
private
def raise_user_error_list(message, resource:)
# your custom behavior, resource will be an active record instance if you are using active record
end
end
end specify the mutation for the operation you wish to change class AppSchema < GraphQL::Schema
use GraphqlDevise::SchemaPlugin.new(
query: Types::QueryType,
mutation: Types::MutationType,
resource_loaders: [
GraphqlDevise::ResourceLoader.new(
User,
only: [:register],
operations: {
register: Mutations::CustomRegister
},
)
]
)
mutation(Types::MutationType)
query(Types::QueryType)
end Let me know if this works for you and I can release a new version of the gem that includes #263 so you can do what I have described here. I think that doing something like what I described in #262 (comment) might be unnecessary if we can already do something similar by specifying the actual mutation and not a base mutation that all other will inherit from. |
Hey @mcelicalderon! When I am disabling custom operation, it is appearing again. |
@vitaliiorlov yes, this behavior is expected. Whenever you specify a custom mutation, we do not make any changes to it compared to when you don't specify one and we set the graphql_devise/lib/graphql_devise/mount_method/operation_preparers/mutation_field_setter.rb Line 14 in b1435ba
|
@mcelicalderon got it. Waiting for merging. Thanks a lot! |
No problem, @vitaliiorlov! v1.4.0 has been released with this change |
What is the problem the enhancement will solve?
Our project has a strict structure of errors with custom GraphQL error classes.
And there is no possibility to customize the error structure in this gem.
Describe the solution you have in mind
You raise this error like this:
It would be great to have full control of this process. I would like to specify my own
DetailedUserError
class for this and also not to passresource.errors.full_messages
as an argument, I need a more detailed object, for example at leastresource.errors
or better you could change the logic in such way I would have to define some proc which will be passed to theraise_user_error_list
method:I hope you understand the issue and looking forward to your answer and hope this suggestion will be implemented.
Thanks, guys for your awesome work!
The text was updated successfully, but these errors were encountered: