How can I create subfolder inside of resolvers / or inside types / or in mutations / ?
I want create sub folder in resolvers/ like:
resolvers/create
resolvers/update
resolvers/delete
resolvers/query
But the file mutation_type.rb dont load the resolvers that are inside the sub folders in resolvers/
Hi! It sounds like you're using Rails, is that right?
Rails has some strong conventions about how filepaths should match the names of Ruby constants which are defined by those files. Maybe the Rails guide will offer some insight! http://guides.rubyonrails.org/autoloading_and_reloading_constants.html
Any solutions for this on Rails?
Thanks!
@tpkonrad, can you give an example of what you're trying to do and what your expectation is? Using sub-directories typically involves namespacing using modules.
@TomasBarry, actually, It seems to be working now. Maybe i forgot to restart Rails the last time I tried. Thank you anyway!


Unfortunately, It seems that we cannot reuse GraphQL type names (even if they are in different modules) :(
Any clues on this?
Thanks


@tpkonrad, I have actually just come across this duplicate name error with a colleague. @rmosolgo may be able to confirm that it is not possible to have two types with the same name even if they are in distinct namespaces.
I suspect this is an actual GraphQL limitation rather than a graphql-ruby limitation?
That's correct, only one type with a given name. By default, GraphQL-Ruby infers a GraphQL name from the Ruby class name. But you can provide one explicitly with graphql_name:
class Types::Admin::User
graphql_name "AdminUser"
end
and it will use the provided value instead of the inferred one (eg, AdminUser instead of User in the above case).
Also, you can implement default_graphql_name in your base class to provide custom logic for inferring the GraphQL name, eg
class Types::BaseObject
def self.default_graphql_name
@default_graphql_name ||= self.name.split("::")[1..-1].join
end
end
(Just an arbitrary example of deriving a GraphQL name from a class name.) You can see the default implementation here: https://github.com/rmosolgo/graphql-ruby/blob/b0e97e759c850cfbc03d75dfbb115f1bc443a985/lib/graphql/schema/member/base_dsl_methods.rb#L86-L95
Hope that helps!
Many thanks @rmosolgo, this solved my problem! :)
Most helpful comment
That's correct, only one type with a given name. By default, GraphQL-Ruby infers a GraphQL name from the Ruby class name. But you can provide one explicitly with
graphql_name:and it will use the provided value instead of the inferred one (eg,
AdminUserinstead ofUserin the above case).Also, you can implement
default_graphql_namein your base class to provide custom logic for inferring the GraphQL name, eg(Just an arbitrary example of deriving a GraphQL name from a class name.) You can see the default implementation here: https://github.com/rmosolgo/graphql-ruby/blob/b0e97e759c850cfbc03d75dfbb115f1bc443a985/lib/graphql/schema/member/base_dsl_methods.rb#L86-L95
Hope that helps!