Skip to content

@Argument resolver fails when type coercion from a single value to SingletonList is involved  #410

@benneq

Description

@benneq

Using Spring GraphQL 1.0.0 with Spring Boot 2.7.0 and Java 17

When passing a single object as argument to a query that expects an array, the argument resolver creates a List<LinkedHashMap>.

Instead it should create a List<Foo> with a single entry.

Here's my code to reproduce the error:

Controller:

@Controller
public class BookController {
    @QueryMapping
    Flux<Book> books(@Argument List<BookOrdering> orderBy) {
        System.out.println(orderBy.get(0).field()); // throws exception
        return Flux.empty();
    }
}

Classes:

public record BookOrdering(BookSort field) {
    public BookOrdering {
        Objects.requireNonNull(field);
    }
}

public enum BookSort {
    NAME,
}

public record Book(String id, String name) {
}

Schema:

type Query {
    books(orderBy: [BookOrdering!]! = []): [Book!]!
}

enum BookSort {
    NAME,
}

input BookOrdering {
    field: BookSort!
}

type Book {
    id: ID!
    name: String!
}

Query:

query {
  books(orderBy: { field: NAME }) {
    id
  }
}

Exception:

java.lang.ClassCastException: class java.util.LinkedHashMap cannot be cast to class com.example.demo.web.book.types.BookOrdering

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions