tyk icon indicating copy to clipboard operation
tyk copied to clipboard

[TT-5612] GraphQL input coercion does not work

Open andrey-nakin opened this issue 2 years ago • 3 comments

Tyke gateway version : 4.1.rc10

In my setting Tyk is working as a GraphQL API gateway in "supergraph" mode and multiple API providers are connected as subgraphs.

I have an input type that accepts a list:

extend type Mutation {
  myMutation(input: MyInput!): Boolean!
}

input MyInput {
  values: [String!]
}

According to GraphQL Specs, it is possible to pass a scalar value when a list is expected. In this case, the scalar value is converted to a singleton list.

For example, the following GraphQL query is correct:

mutation {
  myMutation(
    input: {
      values: "single"
    }
  )
}

because it is implicitly converted to the following one:

mutation {
  myMutation(
    input: {
      values: ["single"]
    }
  )
}

Unfortunately Tyk prevents propagating my request to API provider and the following error is emitted in logs:

time="May 31 07:26:10" level=error msg="http: proxy error: could not render JSON variable, validation failed: /input/values: "single" type should be one of: array,null, got string" api_id=graphql api_name="GraphQL API" mw=ReverseProxy org_id= prefix=proxy server_name= user_id="***" user_ip="***" user_name="***"

andrey-nakin avatar May 31 '22 07:05 andrey-nakin

Hey @andrey-nakin, thanks for reaching out. You are right - input coercion is not working correctly in the available versions of Tyk. We've noticed that earlier and fixed it. The fix is scheduled to be released with version 4.1.0, which is about to go into code freeze. It should be available before end of June.

I'll keep this ticket open for now and once you can verify the behaviour in the next version, let me know if it works, ok?

agata-wit avatar May 31 '22 08:05 agata-wit

The fix is scheduled to be released with version 4.1.0

Great news, thank you! Is the fix committed to master branch for me to take it and use in my own builds of Tyk?

let me know if it works, ok

Sure.

andrey-nakin avatar May 31 '22 10:05 andrey-nakin

@andrey-nakin quick update from the squad. It looks like we implemented input coercion for queries, but somehow we skipped mutations. The team is working on that right now, shouldn't be too much hassle since queries are covered already. Once it's merged into master branch I'll let you know.

agata-wit avatar Jun 01 '22 18:06 agata-wit

This has been fixed in Tyk 4.1.0.

agata-wit avatar Apr 11 '23 14:04 agata-wit