How to handle nested field with arguments in Spring for GraphQL @Controller

Viewed 28

Using org.springframework.boot:spring-boot-starter-graphql and WebMvc, I would like to handle, in the @Controller, nested fields with arguments. E.g.:

query myQuery {
  field1(param1: "value1") {
    field2(param2: "value2") {
      field3
    }
  }
}

The @Controller handles the first field with:

@QueryMapping
public Field1 field1(@Argument param1) {...}

But how to handle the second level field with argument?

1 Answers

I solved it using @SchemaMapping:

@QueryMapping
public Field1 field1(@Argument param1) {...}

@SchemaMapping
public Field2 field2(Field1 field1, @Argument param2) {...}
Related