Skip to content

Allow custom scalar, parsed to different types, to bind onto java.lang.Object #447

Closed
@viico

Description

@viico

Hi,

We are migrating an application to Spring Graphql library from kickstart library, we have working queries/mutations. Our application has several queries to get a list of business entity with an input containing a generic filter object (field, operator and value). This filter input has a value property which is an Object type : depending on the operator (equal or in) it could be a String or a List (or anything else). We have created a GraphQLScalarType Object to represent this field.

We have an issue with this filter input and the scalar type for array values. When we pass an array of values we have this exception (the same works with the kickstart library):

org.springframework.beans.InvalidPropertyException: Invalid property 'value[0]' of bean class [issue.spring.graphql.objectlist.BusinessEntityFilterInput]: Property referenced in indexed property path 'value[0]' is neither an array nor a List nor a Map; returned value was [java.lang.Object@74123110]

There is no issue if the scalar type is used directly as input type.

We pushed a minimal application with tests to reproduce the error :

  1. clone the repo https://github.com/viico/SpringGraphqlObjectVariableArray
  2. launch test of BusinessEntityControllerTests class (it is possible to start the application and send queries)

The application contains 2 queries :

  • filterValueIsInstanceOfList which return true if the value of input filter object is instance of List
  • inputIsInstanceOfList which return true if the input is instance of List

We set up 4 tests :

  • inputIsInstanceOfList_listValue : working test with a an array of 2 values, the input is an instance of List
  • filterValueIsInstanceOfList_stringValue : working test with a String value (return false because it is not an array of values)
  • filterValueIsInstanceOfList_withException : test failing with the exception above when passing a List of 2 values
  • filterValueIsInstanceOfList_withoutVariables : test without exception but with an interrogation, we put the input value directly in the GraphQL query and we have an ArrayValue object, shall we have a List instead ?

After some research we don't see how to solve this issue (the exception) and finish our migration, could you help us ?

Thanks

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions