graphql-java-annotations
graphql-java-annotations copied to clipboard
TypeFunction applied to method also applies to argument
Given:
public class ObjectTypeFunction extends AbstractTypeFunction {
@SuppressWarnings("UnusedVariable")
private static final Logger LOG = LoggerFactory.getLogger(ObjectTypeFunction.class);
public ObjectTypeFunction() {
super(ExtendedScalars.Object, Object.class);
}
@Override
public boolean canBuildType(Class<?> aClass, AnnotatedType annotatedType) {
boolean ret = annotatedType.isAnnotationPresent(GraphQLObjectData.class);
LOG.debug(this + ".canBuildType(" + aClass + ", " + annotatedType + ") = " + ret, new Exception());
return ret;
}
@Override
public GraphQLType buildType(boolean input, Class<?> aClass, AnnotatedType annotatedType, ProcessingElementsContainer container) {
GraphQLType ret = super.buildType(input, aClass, annotatedType, container);
LOG.debug(this + ".buildType(" + aClass + ", " + annotatedType + ") = " + ret, new Exception());
return ret;
}
}
...
@GraphQLField
@GraphQLType(ObjectTypeFunction.class)
public Object domainobject(@GraphQLName("name") @Nonnull String name) {
return new MyDomainObject()
}
- This applies the Object-type to both the argument and the return type, not just the return type.
- Even when I added the check for the extra annotation, it applies to the argument REGARDLESS of the absence of the annotation.
Issue does not arise for a method not so annotated.
Tracing shows that canBuildType() is never called in this code.
java.lang.Exception: null
at custom.ObjectTypeFunction.buildType(ObjectTypeFunction.java:38)
at graphql.annotations.processor.retrievers.fieldBuilders.method.MethodTypeBuilder.build(MethodTypeBuilder.java:52)
at graphql.annotations.processor.retrievers.GraphQLFieldRetriever.getField(GraphQLFieldRetriever.java:77)
at graphql.annotations.processor.typeBuilders.OutputObjectBuilder.getOutputObjectBuilder(OutputObjectBuilder.java:81)
at graphql.annotations.processor.retrievers.GraphQLTypeRetriever.getGraphQLType(GraphQLTypeRetriever.java:86)
at graphql.annotations.processor.retrievers.GraphQLObjectHandler.getGraphQLType(GraphQLObjectHandler.java:32)
at graphql.annotations.processor.GraphQLAnnotations.object(GraphQLAnnotations.java:124)
Bug in GraphQLFieldRetriever: Passes the method's typeFunction into ArgumentBuilder.
List<GraphQLArgument> args = new ArgumentBuilder(method, typeFunction, builder, container, outputType).build();
The method's TypeFunction has no relevance to the arguments; they should be annotated with their own TypeFunction(s) if they want them. Either that or GraphQLFieldRetriever.getTypeFunction() is being too gross by returning the method's type function generally.
In fact, in this code, it looks as if any type function applied to a method applies to the return type AND all arguments, that's a solid bug, because it simply isn't true in general.
Hi @shevek ,
We're helping with project maintenance and reviewing the list of opened PRs and Issues.
This issue was created quite a while ago, we were wondering if you were still interested in the outcome, please let us know if this is the case.
Without an answer by July 1st, 2023, this issue will be closed as "inactive" (and can always be re-opened later on if needed).
Thanks,