-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Field type no longer supports Proc for lazy type resolution? #2874
Comments
Update: If I add a case for def to_type_name(something)
case something
when GraphQL::BaseType, GraphQL::Schema::LateBoundType
something.unwrap.name
when Array
to_type_name(something.first)
when Module
if something.respond_to?(:graphql_name)
something.graphql_name
else
to_type_name(something.name)
end
when String
something.gsub(/\]\[\!/, "").split("::").last
when GraphQL::Schema::NonNull, GraphQL::Schema::List
to_type_name(something.unwrap)
when Proc
to_type_name(something.call)
else
raise "Unhandled to_type_name input: #{something} (#{something.class})"
end
end |
That's right, proc isn't supported in class-based schemas. Previously, procs were called lazily to work around circular loading. Since switching to classes, that should work a bit better, at least with Rails autoloader. If eagerly calling the proc works (as shown in your workaround above), why not just remove the proc? |
Yeah that all makes sense. So is there any way of including a field of a type that hasn't been defined yet? Most of our schema is created dynamically using ActiveRecord introspection. Any help would be much appreciated! Thanks again for all your work on this, it's a life saver! |
Are your types assigned to constants? If so, you can use the string constant name for the type, and it will be constantized as late as possible. For example: field(:post, "Types::Post", null: true) will eventually find # app/graphql/types/post.rb
Types::Post = build_type(::Post) |
That's easier! Thanks so much. |
Describe the bug
until tag v1.10.0.pre3 the docs for fields included this:
I've looked through the changelog and don't see an explicit mention that this has been removed so I'm just wondering if it's intentionally removed or if it's a bug.
If it's intentionally removed, is there a different way of achieving this? Thanks!
Versions
graphql
version: 1.10.6ruby
version:ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin18]
Steps to reproduce
Run the code above
Actual behavior
The text was updated successfully, but these errors were encountered: