Open TomasBarry opened 2 years ago
Hi @TomasBarry , I see your point here, I guess the graphql_name
could be honored in case it is explicitly set in the class instead of concatenating the resource and action. We will have to check the implications of this more carefully before implementing. Are you interested in opening a PR for this?
About using a single mutation to login all resources, there are 2 things that I would like to mention:
additional_operations
key won't add the resource namespace to operations in the gql schema, perhaps you can use this config key to accomplish what you need?resource_klass
set so that the gem knows which AR model to use when building the DB query. Have you considered how having a single mutation to login all resources would work for this part of the code? Hi, I'm having the same issue with two authenticatable models. I thought I could share the same mutation between them by using the GraphqlDevise::ResourceLoader
, but sometimes it used one model or the other (I think this is caused by sharing a class-level instance variable).
I have no issue with duplicating code in the meantime, but I'm worried that I could accidentally share logins between different models. Would it be safe to do this? (in the sense that userLogin
and userLogout
won't collide with adminLogin
and adminLogout
)
class SchemaA < GraphQL::Schema # this one is public
use GraphqlDevise::SchemaPlugin.new(
query: Types::QueryTypeA,
mutation: Types::MutationTypeA,
public_introspection: true,
resource_loaders: [
GraphqlDevise::ResourceLoader.new(
User,
only: %i[
login
logout
register
update_password_with_token
send_password_reset_with_token
confirm_registration_with_token
],
operations: {
login: Mutations::UserLogin,
}
)
]
)
# ...etc
end
class SchemaB < GraphQL::Schema # this one is private
use GraphqlDevise::SchemaPlugin.new(
query: Types::QueryTypeB,
mutation: Types::MutationTypeB,
resource_loaders: [
GraphqlDevise::ResourceLoader.new(
Admin,
only: %i[
login
logout
],
operations: {
login: Mutations::AdminLogin
}
)
]
)
# ...etc
end
What is the problem the enhancement will solve?
In our system, we have multiple different resources. We would like to have a single mutation per operation that can be shared between the various resources.
Essentially, be able to use a Union Type for the authenticable resource where all resources can share a common mutation rather than having to implement one mutation per resource per operation.
Describe the solution you have in mind
Allow for the overriding of
graphql_name
in a custom mutation that inherits from one of theGraphQLDevise
operations:Then the schema file can mount resources like:
Describe alternatives you've considered
One mutation per resource.
Additional context
It seems that there is no customisation of the mutation name available in https://github.com/graphql-devise/graphql_devise/blob/v0.18.2/lib/graphql_devise/mount_method/operation_preparers/default_operation_preparer.rb
It appears that the above ignores any custom
graphql_name
setting in a mutation linked to an operation.