spring-graphql icon indicating copy to clipboard operation
spring-graphql copied to clipboard

bypass arguments parsing when target type is a map

Open koenpunt opened this issue 4 years ago • 2 comments

This allows for unparsed forwarding of graphql arguments, in the case something application specific has to be done with the arguments.

The library already supports passing all of the input as a map, by specifying an argument as @Argument args: Map<String, ?>.

This PR adds support for doing this for individual arguments.

For example to distinguish between unspecified and null values;

input SomeInput {
  name: String
}

type Mutation {
  perform(input: SomeInput!): ...
}

Kotlin:

@MutationMapping
fun perform(@Argument input: Map<String, Any?>): ... {
  if (input.contains("name")) {
    if (input["name"] == null) {
      // throw error
    } else {
      // ...
    }
  }
}

Java:

@MutationMapping
... perform(@Argument Map<String, ?> input) {
  if (input.containsKey("name")) {
    if (input["name"] == null) {
      // throw error
    } else {
      // ...
    }
  }
}

koenpunt avatar Sep 27 '21 12:09 koenpunt

@rstoyanchev and I discussed a few options for this and other related use cases. We've marked #140 for team-discussion and we might come back with proposals. Let's pause this one until #140 is addressed.

bclozel avatar Sep 27 '21 12:09 bclozel

Let's pause this one until #140 is addressed.

Sure. I just figured that since this proposal is more versatile it would have a bigger chance of landing in the framework.

koenpunt avatar Sep 27 '21 12:09 koenpunt

This should be taken care of with #449, but also supported at nested levels.

rstoyanchev avatar Oct 18 '22 11:10 rstoyanchev