Azure API Management validate GraphQL request with object or array variables

Maxime Labelle 5 Reputation points
2023-01-19T08:10:20.35+00:00

I’m using the <validate-graphql-request /> Azure API Management policy. Here is a sample schema:

type Query {
  hello(world: String!): String!
  greetings(world: Greetings): String!
}

input Greetings {
  hello: String!
}

Through API Management, you can test the API by manually writing text into the Query editor and, optionally some Query variables.

Both the hello and greetings query work when specifying static hardcoded arguments in the Query editor. However, only the hello query works when using variables as it expects a SCALAR value. Unfortunately, specifying an object variable for the input argument to the greetings query does not work and raise the following error:

Unable to parse input as a 'Greetings' type. Did you provide a List or Scalar accidentally?

It appears that this error is actually raised by the GraphQL.Net library which might be used internally by Azure API Management. This NuGet has a well-known fix for this error but it appears APIM is not using this fix in its parsing code.

For the record, here are the status of the various queries:

query variables status
query{hello(world: "world!")} N/A
query($world: String!){hello(world: $world)} {"world": "world!"}
query{greetings(world: { hello: "world!" })} N/A
query($world: Greetings){greetings(world: $world)} {"world":{"hello": "world!"}} ❌ `"Variable '$world' is invalid. Unable to parse input as a 'Greetings' type. Did you provide a List or Scalar value accidentally? "'

Is there anything I’m missing?

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
1,698 questions
{count} vote

2 answers

Sort by: Most helpful
  1. Adrian Hall (MSFT) 156 Reputation points Microsoft Employee
    2023-01-19T19:28:57.66+00:00

    Hey Maxime - feel free to reach out to me via email (since I know you have my email address).

    In order to diagnose this, I'd need to see the actual policy, whether you are using Synthetic GraphQL (i.e. a resolver) or pass-through, and what your trace looks like in full. For this reason, I think it's better to do this over email.


  2. Adrian Hall (MSFT) 156 Reputation points Microsoft Employee
    2023-01-26T16:33:59.08+00:00

    We are updating the GraphQL.NET library in our next release, along with a ton of other improvements. Watch the tech community blogs or the Azure API Management release notes (on GitHub) for details when the release happens.

    0 comments No comments