Description
We have a project built using spring-graphql
version 1.0.0-M2
that includes filtering logic using input objects with fields of Enum generics. This approach works fine in M2, but when attempting to upgrade to M4 these Enum input fields were now always blank regardless of what was sent in the query. In the latest M6 version, queries including these fields now result in an INTERNAL_ERROR
similar to this:
org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'filter' on field 'enums[0]': rejected value [ONE]; codes [typeMismatch.target.enums[0],typeMismatch.target.enums,typeMismatch.enums[0],typeMismatch.enums,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [target.enums[0],enums[0]]; arguments []; default message [enums[0]]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Enum' for property 'enums[0]'; nested exception is java.lang.IllegalArgumentException: The target type java.lang.Enum does not refer to an enum]
I was able to recreate the issue we're seeing on a clean spring-boot 2.7.0-M3
project with spring-boot-starter-graphql
and the following:
enum.graphqls
type Query {}
extend type Query {
enums(filter: EnumFilterInput!): [FancyEnum]
}
input EnumFilterInput {
enums: [FancyEnum]
}
enum FancyEnum {
ONE
TWO
THREE
}
EnumController.java
@Controller
public class EnumController {
@QueryMapping
public List<FancyEnum> enums(@Argument EnumFilterInput<FancyEnum> filter) {
return filter.getEnums();
}
}
EnumFilterInput.java
public class EnumFilterInput<E extends Enum<E>> {
private List<E> enums;
public List<E> getEnums() {
return enums;
}
public void setEnums(List<E> enums) {
this.enums = enums;
}
}
FancyEnum.java
public enum FancyEnum {
ONE, TWO, THREE
}
The above project on spring-boot 2.6.6
with spring-graphql 1.0.0-M2
works as expected with the following query:
query {
enums(filter:{
enums:[ONE]
})
}
However on spring-boot 2.7.0-M3
and spring-boot-starter-graphql
(1.0.0-M6
) this query fails with the error given above.
Was this an intended change made to the project or is this an issue that can be resolved in a future release? If it is intended, is there a way to get something similar working that is properly supported by spring-graphql
?
Thanks in advance for any help you can provide.