Mutation in nested object field

25 views Asked by At

I am working with NESTJS + Hasura + GraphiQL to make my DB. I´m trying to mutate a single nested field but preserving the data that it already has. My query is...:

// db model

{
  "id": "ADMIN",
  "full_name": "Admin",
  "email": "[email protected]",
  "config": {
        "isActive": true,
    "general": {
      "sendNotification": true,
    }
  }
},
const query = `
  mutation MyMutation {
    update_profile(
      where: {id: {_eq: ${profile_id_params} }}, 
      _set: {config: ...config, general: {sendNotification: ${tenant_id_body}} }
    ) 
    {
      affected_rows
    }
  }
`;

hasuraResp = await this.hasuraService.mutate(query).then(r => r.data);
// server responds with status 200, but doesn´t update my field;

/* ---------------------------------------------------------------------------------- */

I do have triyed this way, but it overrides the existing data

const query = `
  mutation MyMutation {
    update_profile(
      where: {id: {_eq: ${profile_id_params} }}, 
      _set: {config: ...config, general: {sendNotification: ${can_notify_body} } }) 
    {
      affected_rows
    }
  }
`;

So, how can I change ("mutate") a field that is inside another field? (object key inside object)

0

There are 0 answers