UDG Body request to REST Service

Hello community,

I want to ask regarding the body passed to REST service. For example, if we have a mutation schema like following

type Mutation {
  addUser(num: Int, numPointer: Int, str: String, strPointer: String): ID
}

and we set the body like following

{
  "num": {{.arguments.num}},
  "numPointer": "{{.arguments.numPointer}}",
  "str": "{{.arguments.str}}",
  "strPointer": "{{.arguments.strPointer}}"
}

then we call the following mutation

mutation test3 ($num2:Int, $str: String, $str2: String){
  addUser(numPointer:$num2, str: $str, strPointer:$str2)
}

with each variable has value, but only num that is not declared, then we got the body like following

 {"body":{ "num": , "numPointer": "2", "str": "str2", "strPointer": "str2" }

which is not a valid json. So, can we omit this num field so that it will still be a valid json and it will be better for REST service to know that it is not inputted?

Thanks community

1 Like

Hi @CuriousDuck,

So, can we omit this num field so that it will still be a valid json and it will be better for REST service to know that it is not inputted?

Yes, you can. This is fine on Tyk’s side.

On your REST service’s side, it should be fine e.g if the REST service does not require that field, or has been designed to handle cases where the field is omitted.

1 Like