This repository was archived by the owner on Dec 19, 2023. It is now read-only.
forked from yandooo/graphql-spring-boot
-
Notifications
You must be signed in to change notification settings - Fork 327
Generic Type Is Not Supported in Input Type #496
Labels
Comments
Can you move this issue to the GraphQL-Java-tools project instead. As you’ve already noted through the cause you pasted it’s caused in that project and not in this one.
We’re a small team with limited time and therefore I don’t expect that we have time to solve this anytime soon. However, we welcome PRs and try to approve and merge those as quickly as we can. So if you’re willing and able to help out with this, that would be great!
Groeten,
Michiel
…________________________________
Van: Lyndon <[email protected]>
Verzonden: Thursday, December 24, 2020 6:20:36 PM
Aan: graphql-java-kickstart/graphql-spring-boot <[email protected]>
CC: Subscribed <[email protected]>
Onderwerp: [graphql-java-kickstart/graphql-spring-boot] Generic Type Is Not Supported in Input Type (#496)
Describe the bug
Trying to add a definition factory that can dynamically generate input types containing generic types as fields. But it turns out to be a crash.
To Reproduce
Have a schema like this:
input LanguageInput {
id: Long
}
type Mutation {
test(in: LanguageAudit @Audit(for: "LanguageInput")): String
}
scalar Long
And a corresponding Java resolver and return type like this:
@component
public class Mutation implements GraphQLMutationResolver {
public String test(AuditWrapper<LanguageInput> in) {
return "success";
}
}
public class AuditWrapper<T> {
private T content;
private String operator;
}
I have a factory below to create a dynamic input type. Below is the core part:
private InputObjectTypeDefinition createDefinition(DirectiveWithInputType directive) {
return InputObjectTypeDefinition.newInputObjectDefinition().name(directive.getTypeName())
.inputValueDefinition(new InputValueDefinition("content", new TypeName(directive.forTypeName()))) // Get name from directive audit's "for" argument
.inputValueDefinition(new InputValueDefinition("operator", new TypeName("String")))
.build();
}
Once you try to build the whole schema, it crashes.
Expected behavior
Should parse schema successfully.
Exception Stacks
Caused by: java.lang.ClassCastException: class sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to class java.lang.Class (sun.reflect.generics.reflectiveObjects.TypeVariableImpl and java.lang.Class are in module java.base of loader 'bootstrap')
at graphql.kickstart.tools.util.UtilsKt.unwrap(Utils.kt:36)
at graphql.kickstart.tools.GenericType$RelativeTo.parameterizedDeclaringTypeOrSuperType(GenericType.kt:120)
at graphql.kickstart.tools.GenericType$RelativeTo.unwrapGenericType(GenericType.kt:102)
at graphql.kickstart.tools.TypeClassMatcher.match(TypeClassMatcher.kt:28)
at graphql.kickstart.tools.TypeClassMatcher.match(TypeClassMatcher.kt:23)
at graphql.kickstart.tools.SchemaClassScanner.handleNewType(SchemaClassScanner.kt:341)
at graphql.kickstart.tools.SchemaClassScanner.handleFoundType(SchemaClassScanner.kt:321)
at graphql.kickstart.tools.SchemaClassScanner.handleFoundType(SchemaClassScanner.kt:286)
at graphql.kickstart.tools.SchemaClassScanner.scanResolverInfoForPotentialMatches(SchemaClassScanner.kt:274)
at graphql.kickstart.tools.SchemaClassScanner.handleRootType(SchemaClassScanner.kt:129)
at graphql.kickstart.tools.SchemaClassScanner.scanForClasses(SchemaClassScanner.kt:71)
at graphql.kickstart.tools.SchemaParserBuilder.scan(SchemaParserBuilder.kt:154)
at graphql.kickstart.tools.SchemaParserBuilder.build(SchemaParserBuilder.kt:195)
at com.lyndon.demo.graphql.GraphQLConfig.getGraphQL(GraphQLConfig.java:45)
at com.lyndon.demo.graphql.GraphQLConfig$$EnhancerBySpringCGLIB$$7db0c7a6.CGLIB$getGraphQL$0(<generated>)
at com.lyndon.demo.graphql.GraphQLConfig$$EnhancerBySpringCGLIB$$7db0c7a6$$FastClassBySpringCGLIB$$e26d0083.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
at com.lyndon.demo.graphql.GraphQLConfig$$EnhancerBySpringCGLIB$$7db0c7a6.getGraphQL(<generated>)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 109 more
Possible reason:
I've checked the current implementation and found that in SchemaClassScanner.kt:339, you have this code:
val inputValueJavaType = findInputValueType(inputValueDefinition.name, inputGraphQLType, javaType.unwrap())
This javaType.unwrap() will discard generic type information and then when trying to match type field and its Java type, you will get a "T" as field's type, which results in the final crash. Here we need to get the real type (LanguageInput in my case) behind the generic label.
Actually this happens every time when you try to put a Java type with generic fields as a variable's type.
Hope this issue can be fixed soon. Otherwise I have to manually define types myself both in schema and Java implementation.
Thank you.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub<#496>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ADHEKQGATQK3ZU5M4SCC52DSWNZ6JANCNFSM4VIMV44A>.
|
Sorry, didn't notice that this issue is from another project. I'll forward it to GraphQL-Java-tools then. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Describe the bug
Trying to add a definition factory that can dynamically generate input types containing generic types as fields. But it turns out to be a crash.
To Reproduce
Have a schema like this:
And a corresponding Java resolver and return type like this:
I have a factory below to create a dynamic input type. Below is the core part:
Once you try to build the whole schema, it crashes.
Expected behavior
Should parse schema successfully.
Exception Stacks
Possible reason:
I've checked the current implementation and found that in
SchemaClassScanner.kt:339
, you have this code:This
javaType.unwrap()
will discard generic type information and then when trying to match type field and its Java type, you will get a "T" as field's type, which results in the final crash. Here we need to get the real type (LanguageInput
in my case) behind the generic label.Actually this happens every time when you try to put a Java type with generic fields as a variable's type.
Hope this issue can be fixed soon. Otherwise I have to manually define types myself both in schema and Java implementation.
Thank you.
The text was updated successfully, but these errors were encountered: