Repository navigation
graphql.AssertException is being thrown where previously it wasn't #780
Description
Description
With a schema like this
Previously we could execute a query like:
query quests {
quests(
filter: {
states: ["ONGOING"]
}
) {
questId
}
}
Now whenever there is an existing entry that is child of Questline in the database in the specific state that you query for, an error is thrown ( so let's say there is an entry in the database for EpicQuestline that has status ONGOING, if you query for status: ONGOING ) , it would throw an error:
graphql.AssertException: You have asked for named object type 'Questline' but it's not an object type but rather a 'graphql.schema.GraphQLInterfaceType'
at graphql.Assert.assertTrue(Assert.java:78)
at graphql.schema.GraphQLSchema.getObjectType(GraphQLSchema.java:295)
at graphql.kickstart.tools.DictionaryTypeResolver.getType(DictionaryTypeResolver.kt:27)
at graphql.execution.ResolveType.resolveAbstractType(ResolveType.java:62)
at graphql.execution.ResolveType.resolveTypeForInterface(ResolveType.java:53)
at graphql.execution.ResolveType.resolveType(ResolveType.java:39)
at graphql.execution.ExecutionStrategy.resolveType(ExecutionStrategy.java:720)
at graphql.execution.ExecutionStrategy.completeValue(ExecutionStrategy.java:483)
at graphql.execution.ExecutionStrategy.completeValueForList(ExecutionStrategy.java:586)
at graphql.execution.ExecutionStrategy.completeValueForList(ExecutionStrategy.java:543)
at graphql.execution.ExecutionStrategy.completeValue(ExecutionStrategy.java:469)
at graphql.execution.ExecutionStrategy.completeField(ExecutionStrategy.java:435)
at graphql.execution.ExecutionStrategy.lambda$resolveFieldWithInfo$1(ExecutionStrategy.java:215)
at java.base/java.util.concurrent.CompletableFuture.uniApplyNow(CompletableFuture.java:684)
at java.base/java.util.concurrent.CompletableFuture.uniApplyStage(CompletableFuture.java:662)
at java.base/java.util.concurrent.CompletableFuture.thenApply(CompletableFuture.java:2168)
at graphql.execution.ExecutionStrategy.resolveFieldWithInfo(ExecutionStrategy.java:214)
at graphql.execution.AsyncExecutionStrategy.execute(AsyncExecutionStrategy.java:55)
at graphql.execution.Execution.executeOperation(Execution.java:161)
... 126 common frames omitted
Additional information:
A colleague of mine mentioned that this issue seems familiar to him and last time something like this was encountered the solution was somewhere in the dependency versions of hibernate-orm plugin and graphql-enhance plugin ( they were incompatible and once the versions were matched the issue was fixed.) This is currently not the case since i checked the versions of the aforementioned dependencies and it seems the issue is coming from somewhere else.
A list of all concrete Quest/Questline objects that inherit the Quest interface ( i.e. a list that has EpicQuestline and SpecificQuest from the example schema ).
A graphql.AssertException saying You have asked for named object type 'Questline' but it's not an object type but rather a 'graphql.schema.GraphQLInterfaceType' is thrown instead .
Steps to reproduce the bug
-
Have a similar schema
-
Have a query like:
query quests {
quests(
filter: {
states: ["ONGOING"]
}
) {
questId
}
}
- A resolver function like : this
Note:
The repository provided above might not have enough information. If you need more information please let me know and I will provide it to the best of my ability and ASAP.
Since this is one of the first ever github issues in my career please excuse my negligence!
Activity
TsvetomirValchev commentedon Apr 5, 2024
Hello!
is there any updates on this?
drewhk commentedon May 23, 2024
Hi @TsvetomirValchev, I am not sure it helps you, but I had a similar problem when using Hibernate. The issue was that the returned object was actually a Hibernate proxy object, that is a type subclassing the original interface, but not belonging to the set of subtypes GraphQL kickstart knows (since the proxy class is generated at runtime). If you use Hibernate lazy loading, or any other library that may proxy your original objects you might experience this strange issue. I am not sure if this is the case for you, but maybe a future reader is unblocked by my comment :)
TsvetomirValchev commentedon May 23, 2024
Hi @drewhk! Do you mind sharing how you fixed it ? I think you might have hit the spot for why this issue is happening but I could not work out a way to fix it. A colleague of mine previously told me there was a similar issue and it was something related to some libraries' interaction with Hibernate.
drewhk commentedon May 23, 2024
So, in my case there was a GraphQL type
Outerwhich had a fieldinnerof interface typeInner. Since this field was lazy loaded, I had to create aFieldResolver<Outer>with agetInnermethod that just took theinnerfield of the object and calledHibernate.unproxyon it. That is I did not expose theinnerfield directly (as it could contain a proxy), but wrapped the access in a dedicated field resolver that just unproxied the object in that field. Sorry if it is a bit terse, I am in a hurry right now :)TsvetomirValchev commentedon May 23, 2024
Thank you for the fast response i will try this fix and will post an update if it fixed my issue as well!
Thanks again!
oryan-block commentedon Oct 3, 2026
This is most likely caused by runtime proxies.
DictionaryTypeResolverwalks the runtime class's supertypes until it finds a mapped GraphQL type. A Hibernate lazy proxy subclassesQuestlinerather thanEpicQuestline, so the first match is the interface and graphql-java'sgetObjectTypethrows theAssertException. As @drewhk described above, unproxy the object in a field resolver (Hibernate.unproxy(...)) before returning it. Closing.