Skip to content
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

Nesting resolvers of the same type #30

Open
kiskoza opened this issue Mar 3, 2021 · 3 comments
Open

Nesting resolvers of the same type #30

kiskoza opened this issue Mar 3, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@kiskoza
Copy link
Contributor

kiskoza commented Mar 3, 2021

Recently I ran into a cyclical load error with resolvers. After searching for a solution, I found that this it a known issue and could be resolved by an easy change described here: https://graphql-ruby.org/fields/resolvers.html#nesting-resolvers-of-the-same-type

Then it popped to my mind why we don't warn people about this potential issue with rubocop? If it sounds reasonable to you, I'd like to write a new cop suggesting that you should have a string type definition in resolvers.

# Resovers should use strings for type definitions. See: https://graphql-ruby.org/fields/resolvers.html#nesting-resolvers-of-the-same-type
# 
# @example
#   # good
# 
#   module Resolvers
#     class TasksResolver < GraphQL::Schema::Resolver
#       type '[Types::TaskType]', null: false
# 
#       def resolve
#         []
#       end
#     end
#   end
# 
#   # bad
# 
#   module Resolvers
#     class TasksResolver < GraphQL::Schema::Resolver
#       type [Types::TaskType], null: false
# 
#       def resolve
#         []
#       end
#     end
#   end
@DmitryTsepelev
Copy link
Owner

Hi @kiskoza, sounds reasonable, I'll be happy to review this PR!

@DmitryTsepelev DmitryTsepelev added the waiting for response Further information is requested label Mar 28, 2021
@kiskoza
Copy link
Contributor Author

kiskoza commented Mar 29, 2021

Cool. I'm going to implement it soon

@DmitryTsepelev DmitryTsepelev added enhancement New feature or request and removed waiting for response Further information is requested labels Feb 14, 2023
@RasimKhusaenov
Copy link
Contributor

@DmitryTsepelev, hey! I did some research on this. This problem is not repeated in every resolver, and if there is a connection_type, we cannot convert it to string. In addition, graphql-ruby has added a more detailed error message for this case (https://github.com/rmosolgo/graphql-ruby/blob/v2.0.21/lib/graphql/schema/field.rb#L584):

Can't determine the return type for Task.tasks (it has `resolver: Resolvers::TasksResolver`, perhaps that class is missing a `type ...` declaration, or perhaps its type causes a cyclical loading issue)

Should we still add a new cop?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants