This happens when graphiql is initialized and also when I execute the introspection query myself, e.g.:
schema.execute(GraphQL::Introspection::INTROSPECTION_QUERY)
Not sure how to debug this one. Stack trace follows:
undefined method `unwrap' for nil:NilClass
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/static_validation/type_stack.rb:110:in `push'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/static_validation/type_stack.rb:200:in `call'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/language/visitor.rb:65:in `block in apply_hooks'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/language/visitor.rb:65:in `each'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/language/visitor.rb:65:in `reduce'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/language/visitor.rb:65:in `apply_hooks'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/language/visitor.rb:54:in `begin_visit'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/language/visitor.rb:45:in `visit_node'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/language/visitor.rb:47:in `block in visit_node'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/language/visitor.rb:47:in `each'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/language/visitor.rb:47:in `visit_node'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/language/visitor.rb:47:in `block in visit_node'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/language/visitor.rb:47:in `each'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/language/visitor.rb:47:in `visit_node'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/language/visitor.rb:39:in `visit'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/static_validation/validator.rb:39:in `block in validate'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/tracing.rb:57:in `block in trace'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/tracing.rb:71:in `call_tracers'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/tracing.rb:57:in `trace'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/static_validation/validator.rb:25:in `validate'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/query/validation_pipeline.rb:80:in `ensure_has_validated'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/query/validation_pipeline.rb:34:in `valid?'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/query.rb:228:in `valid?'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/analysis/analyze_query.rb:11:in `block (2 levels) in analyze_multiplex'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/analysis/analyze_query.rb:10:in `map'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/analysis/analyze_query.rb:10:in `block in analyze_multiplex'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/tracing.rb:57:in `block in trace'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/tracing.rb:71:in `call_tracers'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/tracing.rb:57:in `trace'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/analysis/analyze_query.rb:8:in `analyze_multiplex'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/execution/multiplex.rb:173:in `block in instrument_and_analyze'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/execution/instrumentation.rb:29:in `block (2 levels) in apply_instrumenters'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/execution/instrumentation.rb:46:in `block (2 levels) in each_query_call_hooks'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/execution/instrumentation.rb:41:in `each_query_call_hooks'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/execution/instrumentation.rb:45:in `block in each_query_call_hooks'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/execution/instrumentation.rb:58:in `call_hooks'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/execution/instrumentation.rb:44:in `each_query_call_hooks'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/execution/instrumentation.rb:27:in `block in apply_instrumenters'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/execution/instrumentation.rb:58:in `call_hooks'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/execution/instrumentation.rb:26:in `apply_instrumenters'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/execution/multiplex.rb:166:in `instrument_and_analyze'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/execution/multiplex.rb:68:in `block in run_queries'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/tracing.rb:57:in `block in trace'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/tracing.rb:71:in `call_tracers'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/tracing.rb:57:in `trace'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/execution/multiplex.rb:58:in `run_queries'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/execution/multiplex.rb:48:in `run_all'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/schema.rb:338:in `block in multiplex'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/schema.rb:958:in `with_definition_error_check'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/schema.rb:337:in `multiplex'
.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/graphql-1.8.0.pre10/lib/graphql/schema.rb:314:in `execute'
.../work/suede/app/controllers/api/graphql/graphql_controller.rb:63:in `block (2 levels) in schema'
Update. This is not limited to the introspection query.
Update #2. In debugging into this, I can see that in OperationDefinitionStrategy#push, we have:
object_type = stack.schema.root_type_for_operation(node.operation_type)
where node.operation_type is "query" and the schema.root_type_for_operation call is returning nil. So my query object is not set in the schema for some reason. I noticed that GraphQL::Schema has an attr_accessor query and a query()method. The query() method is called on initialization of my Schema subclass and I think the attr_accessor :query is being called in the root_type_for_operation call.
My Schema class is declared like so:
module MyProj
module GraphQL
class NewSchema < ::GraphQL::Schema
query MyProj::GraphQL::Types::Query
...
Clearly I'm doing something wrong here. Can anyone tell me what that is?
So the thing I was doing wrong was that I was calling execute on an instance of my Schema rather than on the class. This is what I was doing pre-1.8. Did this change in 1.8 and did I miss a piece of documentation somewhere?
Thanks for updating this issue with your findings! Glad you found the solution, and sorry about the mishap, how frustrating 馃槚
Did this change in 1.8?
Yes, it did, in a sense.
Previously, schemas were created using GraphQL::Schema.define, and now they're created using class ... < GraphQL::Schema.
In both cases, they create an object which responds to .execute(...). Previously, the returned object happened to be an _instance_ of GraphQL::Schema, but now, the object is a _subclass_ of GraphQL::Schema. Calling Schema.new was not previously supported, nor is it supported now!
This design change isn't explicitly documented, except that the style for creating a Schema has changed. I hope that clarifies the issue a bit, and if you think some specific documentation should be improved or added, feel free to leave another comment or open an issue/PR!
I think your Getting Started page needs some updating then. I was running into this issue.
I'm still having this problem. Can someone explain what changes they made in the code to solve this?
Apologies for bringing this relatively old issue back from the dead, but this is the only useful result for graphql-ruby "undefined method unwrap" on Google.
I'm having the same issue on v1.8.10. Here is my stack trace:
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/static_validation/type_stack.rb:110:in `push'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/static_validation/type_stack.rb:200:in `call'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/language/visitor.rb:65:in `block in apply_hooks'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/language/visitor.rb:65:in `each'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/language/visitor.rb:65:in `reduce'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/language/visitor.rb:65:in `apply_hooks'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/language/visitor.rb:54:in `begin_visit'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/language/visitor.rb:45:in `visit_node'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/language/visitor.rb:47:in `block in visit_node'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/language/visitor.rb:47:in `each'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/language/visitor.rb:47:in `visit_node'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/language/visitor.rb:47:in `block in visit_node'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/language/visitor.rb:47:in `each'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/language/visitor.rb:47:in `visit_node'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/language/visitor.rb:39:in `visit'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/static_validation/validator.rb:39:in `block in validate'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/tracing.rb:62:in `block in trace'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/tracing.rb:76:in `call_tracers'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/tracing.rb:62:in `trace'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/static_validation/validator.rb:25:in `validate'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/query/validation_pipeline.rb:73:in `ensure_has_validated'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/query/validation_pipeline.rb:45:in `internal_representation'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/query.rb:205:in `irep_selection'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/schema/member/instrumentation.rb:22:in `before_query'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/execution/instrumentation.rb:58:in `public_send'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/execution/instrumentation.rb:58:in `block in call_hooks'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/execution/instrumentation.rb:57:in `each'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/execution/instrumentation.rb:57:in `call_hooks'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/execution/instrumentation.rb:44:in `each_query_call_hooks'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/execution/instrumentation.rb:27:in `block in apply_instrumenters'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/execution/instrumentation.rb:70:in `call_hooks'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/execution/instrumentation.rb:26:in `apply_instrumenters'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/execution/multiplex.rb:166:in `instrument_and_analyze'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/execution/multiplex.rb:68:in `block in run_queries'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/tracing.rb:62:in `block in trace'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/tracing.rb:76:in `call_tracers'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/tracing.rb:62:in `trace'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/execution/multiplex.rb:58:in `run_queries'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/execution/multiplex.rb:48:in `run_all'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/schema.rb:342:in `block in multiplex'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/schema.rb:1079:in `with_definition_error_check'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/schema.rb:341:in `multiplex'
/usr/local/bundle/gems/graphql-1.8.10/lib/graphql/schema.rb:318:in `execute'
/usr/src/app/app/controllers/graphql_controller.rb:11:in `execute'
The schema in question:
class MyActualSchema < GraphQL::Schema
max_depth 50
# Both `Types::MutationType` and `Types::QueryType` are defined, and both work in development.
mutation(Types::MutationType)
query(Types::QueryType)
end
And graphql_controller.rb:11:
# Where MyActualSchema is the name of my schema class
result = MyActualSchema.execute(query, variables: variables, context: context, operation_name: operation_name)
I suspected originally it was because I was using an undefined type somewhere but that doesn't seem to be the case. This only happens with RAILS_ENV=production, so classes are cached among other things. Any help would be greatly appreciated.
And if you'd rather me open a new issue, I'll gladly do so. Thanks!
Since there hasn't been any activity on this recently, I am going to open a new issue.
Most helpful comment
I think your Getting Started page needs some updating then. I was running into this issue.