spring-projects / spring-graphql

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

@EntityMapping method cannot resolve Kotlin List argument #1018

Closed klys-equinix closed 3 months ago

klys-equinix commented 3 months ago

I have a method with signature:

@EntityMapping
    fun floors(
        representations: List<Map<String, Object>>
    ): Flux<Floors>

Calling it like this:

query MyQuery {
  _entities(representations: [{code: "AM5", name: "0G", __typename: "Floors"}]) {
    ... on Floors {
      __typename
      code
      name
      spatialFloorId
    }
  }
}

Causes an error:

{
  "errors": [
    {
      "message": "Could not resolve parameter [0] in public final reactor.core.publisher.Flux<com.equinix.vdc.spatial.generated.graphql.model.Floors> com.equinix.vdc.spatial.controller.floor.FloorsController.floors(java.util.List<? extends java.util.Map<java.lang.String, ?>>): No suitable resolver",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "_entities",
        0
      ],
      "extensions": {
        "classification": "INTERNAL_ERROR"
      }
    }
  ],
  "data": {
    "_entities": [
      null
    ]
  }
}
klys-equinix commented 3 months ago

Binding with the DataFetchingEnvironment works fine:

@EntityMapping
    fun floors(
        env: DataFetchingEnvironment
    ): Flux<Floors>

And i can see that this env contain correct representations in debugger, but i cannot access them since the EntityBatchDataFetchingEnvironment is not public

klys-equinix commented 3 months ago

This is working correctly if i force kotlin to use Java collections:

@EntityMapping
    fun floors(
        env: DataFetchingEnvironment,
        representations: java.util.List<Map<String, String>>
    ): Flux<Floors>

Seems like the issue is in

EntityArgumentsMethodArgumentResolver::supportsParameter

rstoyanchev commented 3 months ago

There is a fix in 1.3.2-SNAPSHOT now if you'd like to give it a try.