I'm having an issue with Apollo handling the respo...
# apollo-kotlin
s
I'm having an issue with Apollo handling the response to a mutation from Hasura. "com.apollographql.apollo3.exception.JsonDataException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at path data.update_user_role_many". They context is a bit long, so I'll put it in the thread.
mutation:
Copy code
mutation updateUser($id: uuid!, $user: user_set_input!, $addRoles: [user_role_insert_input!]!, $updateRoles: [user_role_updates!]!) {
    update_user_by_pk(
        _set: $user,
        pk_columns: {id: $id}
    ) {
        id
    }
    insert_user_role(objects: $addRoles) {
        affected_rows
    }
    update_user_role_many(updates: $updateRoles) {
        affected_rows
    }
}
relevant schema:
Copy code
type mutation_root {
  ...
  update_user_role_many("updates to execute, in order" updates: [user_role_updates!]!): [user_role_mutation_response]
  ...
}

"""
response of any mutation on the table "user_role"
"""
type user_role_mutation_response {
  """
  number of rows affected by the mutation
  """
  affected_rows: Int!

  """
  data from the rows affected by the mutation
  """
  returning: [user_role!]!
}
response from server:
Copy code
{
  "data": {
    "update_user_by_pk": {
      "id": "62f59281-28a0-4ac0-8c2d-35a3e3d61bb2"
    },
    "insert_user_role": {
      "affected_rows": 1
    },
    "update_user_role_many": {
      "affected_rows": 0
    }
  }
}
m
Looks like a backend issue to me. •
mutation_root.update_user_role_many
is a list •
data.update_user_role_many
is returned as a JsonObject
There is input coercion for list with just one item but I don't thing there is output coercion
s
Yeah, it looks like they're generating the schema incorrectly.
m
This is the part about input coercion:
Copy code
If the value passed as an input to a list type is not a list and not the null value, then the result of input coercion is a list of size one
Output coercion is relatively explicit that it's not allowed:
Copy code
In particular, if a non-list is returned, the coercion should fail, as this indicates a mismatch in expectations between the type system and the implementation.
I'd ask the backend team if they can do something about it. You could rewrite the json on the fly or change the schema client side to match the Json but both those things are quite dangerous in the long term
s
Yeah, sounds like a hasura bug. I guess I need to avoid
update_*_many
. I'll file a bug with them. Thanks for your help!
👍 1
m
Sure thing! If you file a bug, share it here, it's interesting to understand the root cause
s
gratitude thank you 1
Thanks again for your help.
💙 1