spring-projects / spring-graphql

Spring Integration for GraphQL
https://spring.io/projects/spring-graphql
Apache License 2.0
1.53k stars 305 forks source link

An empty List in the variable input is converted to null #323

Closed wjohnstonjr closed 2 years ago

wjohnstonjr commented 2 years ago

We have an input type that has a list of Int:

input AnInput { id: ID! aList: [Int] }

The variables that are passed look like this:

{ "id": "3a9b3c5b-be6b-4f6a-bf0d-067681bb950c", "aList": [] }

The value of aList in our handler is null when we are expecting an empty list. I would expect a null value if it was set to null in the variables:

{ "id": "3a9b3c5b-be6b-4f6a-bf0d-067681bb950c", "aList": null }

Or if the value was not present in the variables:

{ "id": "3a9b3c5b-be6b-4f6a-bf0d-067681bb950c" }

It looks like the code in GraphQlArgumentInitializer.visitArgumentMap() does not handle the empty list correctly.

dugenkui03 commented 2 years ago

@wjohnstonjr Sound like same problem #301

wjohnstonjr commented 2 years ago

Yup, looks just like it.

rstoyanchev commented 2 years ago

@wjohnstonjr if you can, please give the snapshot a try.

wjohnstonjr commented 2 years ago

I tried the snapshot and I get this error:

`*** APPLICATION FAILED TO START


Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

org.springframework.graphql.boot.GraphQlWebMvcAutoConfiguration.graphQlRouterFunction(GraphQlWebMvcAutoConfiguration.java:120)

The following method did not exist:

org/springframework/graphql/web/webmvc/GraphiQlHandler.<init>(Ljava/lang/String;)V

The method's class, org.springframework.graphql.web.webmvc.GraphiQlHandler, is available from the following locations:

jar:file:/C:/repository/org/springframework/graphql/spring-graphql/1.0.0-SNAPSHOT/spring-graphql-1.0.0-SNAPSHOT.jar!/org/springframework/graphql/web/webmvc/GraphiQlHandler.class

The class hierarchy was loaded from the following locations:

org.springframework.graphql.web.webmvc.GraphiQlHandler: file:/C:/repository/org/springframework/graphql/spring-graphql/1.0.0-SNAPSHOT/spring-graphql-1.0.0-SNAPSHOT.jar

Action:

Correct the classpath of your application so that it contains a single, compatible version of org.springframework.graphql.web.webmvc.GraphiQlHandler

`

wjohnstonjr commented 2 years ago

@rstoyanchev, I got past the error by setting spring.graphql.graphiql.enabled=false. Is this a known issue?

I tested it and it is working. I get the empty List when I passed [].

bclozel commented 2 years ago

@wjohnstonjr are you using the latest 2.7.0-SNAPSHOT Spring Boot version?

wjohnstonjr commented 2 years ago

@bclozel, I am not using 2.7.0-SNAPSHOT and I do not have access to the snapshot or milestone repositories at work. I put in a request to get access to them but it will probably take some time. Will this fix only be in the 2.7.0 releases?

bclozel commented 2 years ago

I don't understand. How are you using Spring GraphQL if you don't have access to milestones nor snapshots? There is no GA version yet.

From a Spring Boot auto-configuration perspective, you should now use the official Spring Boot starter for Spring GraphQL, as the former experimental one is now defunct.

wjohnstonjr commented 2 years ago

I manually downloaded the 1.0.0-M4 versions and added them to our local Artifactory.

bclozel commented 2 years ago

Then you'll be able to test this with Spring GraphQL 1.0.0-M6 and Spring Boot 2.7.0-M3 in a few days.

wjohnstonjr commented 2 years ago

I was able to test with 2.7.0-SNAPSHOT and it is working.