hasura multilevel nested mutations

Viewed 20

I try to upsert 2-level nested mutation:

department: { subdivisions: { users: { department, subdivision } } }

User was updated, but user.department=null.

And users returning was empty.

Full query:

mutation MyMutation($d: [department_insert_input!]!) {
  insert_department(objects: $d,
    on_conflict: {
      constraint: department_u_onec_id,
      update_columns: description
    }
  ) {
    returning {
      id
      subdivisions {
        id name
        users {
          id
          login
          subdivision
          department
      }}
      
    }
  }
}

Variables:

{
  "d": {
    "onec_id": "test1",
    "title": "test",
    "subdivisions": {
      "data": [
        {
          "description": "test1",
          "users": {
            "data": {
              "login": "test1",
              "role": 1,
              "onec_id": "test1"
            },
            "on_conflict": {
              "constraint": "user_login_uindex",
              "update_columns": [
                "role"
              ]
            }
          }
        }
      ],
      "on_conflict": {
        "constraint": "subdivision_u_onec_id",
        "update_columns": [
          "description",
        ]
      }
    },
  }
}

Result:

{
    "insert_department": {
        "returning": [
            {
                "id": 6,
                "subdivisions": [
                    {
                        "id": 10,
                        "name": "test1",
                        "users": [
                           {
                               "id": 35,
                                "login": "test1",
                                "subdivision": 10,
                                "department": null
                            }
                        ]
                    }
                ]
            }
        ]
    }
}

Can I set users.{department, subdivision} in one query, if I not know it in advance?

1 Answers

I duplicated the users section into departments and it works. Variables:

{
  "department": {
     ...
     "users":{
       "data":[{"login":"test1","role":2}],
       "on_conflict":{"constraint":"user_login_uindex",
       "update_columns":[ "department"]}}
     ...
     "subdivisions": { users: { ... }}
  }
}
Related