We just upgraded from 1.8.11 to 1.9.4 and now we have problems with debugging errors during our rspec tests.
e.g. we have an exception occuring during the first test:
NameError:
uninitialized constant Types::ApplicationType
In 1.8.11 this error would occur repeatedly during the whole test suite run.
Since 1.9.4 only the first spec fails with the error above. All following specs are failing with
RuntimeError:
Unexpected parent_type:
Does this behavior has something to do with schema caching?
How can we get better errors in this case?
We narrowed down the issue.
When defining a type:
class Customer < GraphQL::Schema::Object
field :someField, GraphQL::Types::String, null: false, resolve: UnknownClass
end
This results in a NameError the first time, but Customer is still defined.
For the following specs the schema seems valid for the validator.
When GraphqlSchema.execute is called the error RuntimeError: Unexpected parent_type: occurs.
Seeing the same issue on (1.9.6)
Hi I had the same issue with:
class UserType < Types::BaseObject
field :id, null: false
end
I fixed it by adding the field ID type.
class UserType < Types::BaseObject
field :id, ID, null: false
end
Hope this helps
Hi I had the same issue with:
class UserType < Types::BaseObject field :id, null: false endI fixed it by adding the field ID type.
class UserType < Types::BaseObject field :id, ID, null: false endHope this helps
As long as your definition is valid, everything is fine.
But if you have an error, you will get the error message mentioned above.
Hi! Please reopen with the full backtrace along and full error messages if you want to debug further. Hard to debug without seeing that.
I ran into this one and realized I was using null: false instead of required: true.
Had a similar issue when I accidentally inherited from BaseType instead of BaseObject, but I had no hint that was what was wrong. Just RuntimeError:
Unexpected parent_type:
I was looking at the backtrace, but I always get a little tangled in the visitor pattern (my failing there) and I'm having trouble seeing where to hook in and raise that might call this out more clearly.
I ran into this issue when I accidentally removed a type file that was referenced by a parent object type. Bringing the missing type file back fixed the issue for me.
I had the same issue and it got fixed for me, because I accidently had the wrong file name (Autoloading issue).
Previously, my file was named trackable_union.rb and the class was Trackable. After renaming the trackable_union.rb to trackable.rb it worked for me.
Most helpful comment
We narrowed down the issue.
When defining a type:
class Customer < GraphQL::Schema::Object
field :someField, GraphQL::Types::String, null: false, resolve: UnknownClass
end
This results in a NameError the first time, but Customer is still defined.
For the following specs the schema seems valid for the validator.
When GraphqlSchema.execute is called the error
RuntimeError: Unexpected parent_type:occurs.