graphql – Return Type of Hasura’s Auto-Generated *_many Mutations Varies with Input

I’m using Hasura to execute GraphQL mutations.

When I run the following mutation:

mutation UpdateProjects($updates: [project_updates!]!) {
  update_project_many(updates: $updates) {
    affected_rows
  }
}

If $updates is an empty array, I receive:

{
  "data": {
    "update_project_many": {
      "affected_rows": 0
    }
  }
}

If $updates is a non-empty array, I receive:

{
  "data": {
    "update_project_many": [
      {
        "affected_rows": 1
      },
      {
        "affected_rows": 1
      }
    ]
  }
}

I noticed that the return type of update_project_many changes based on the content of $updates: it returns an object when the array is empty and an array when it’s not.

Is this the expected behavior?

When using graphql-codegen to generate types for this mutation, it expects an array. However, when $updates is empty, the response is an object, which causes issues in my application.

  update_project_many?: Maybe<
    Array>
  >

I tried looking up Hasura but couldn’t find anything.

Read more here: Source link