dgraph icon indicating copy to clipboard operation
dgraph copied to clipboard

[BUG]: Deep update should not be possible if mandatory fields are not present in the input

Open benwoodward opened this issue 1 year ago • 2 comments

What version of Dgraph are you using?

v22.0.2

Tell us a little more about your go-environment?

I'm using the standalone docker image

Have you tried reproducing the issue with the latest release?

Yes

What is the hardware spec (RAM, CPU, OS)?

not relevant

What steps will reproduce the bug?

schema:

type Project {
  id: ID!
  members: [Member!]
}

type Member {
  id: ID!
  nickname: String!
  favoriteColor: String!
  project: Project! @hasInverse(field: members)
}

Perform deep (nested) update:

mutation UpdateProject($input: UpdateProjectInput!) {
  updateProject(input: $input) {
    project {
      id
      members {
        id
      }
    }
  }
}
{
  "input": {
    "filter": {
      "id": [
        "0x42074"
      ]
    },
    "set": {
      "members": [
        {
          "favoriteColor": "orangey red" // nickname should be here too as it is a required field
        }
      ]
    }
  }
}

result:

{
  "data": {
    "updateProject": {
      "project": [
        {
          "id": "0x42074",
          "members": [
            {
              "id": "0x325aa2"
            }
          ]
        }
      ]
    }
  },
  "extensions": {
    "touched_uids": 22,
    "tracing": {
      "version": 1,
      "startTime": "2023-04-03T23:52:32.2684963Z",
      "endTime": "2023-04-03T23:52:32.3478531Z",
      "duration": 79356900,
      "execution": {
        "resolvers": [
          {
            "path": [
              "updateProject"
            ],
            "parentType": "Mutation",
            "fieldName": "updateProject",
            "returnType": "UpdateProjectPayload",
            "startOffset": 266200,
            "duration": 79044100,
            "dgraph": [
              {
                "label": "preMutationQuery",
                "startOffset": 0,
                "duration": 0
              },
              {
                "label": "mutation",
                "startOffset": 563900,
                "duration": 28755000
              },
              {
                "label": "query",
                "startOffset": 39370300,
                "duration": 39924500
              }
            ]
          }
        ]
      }
    }
  }
}

Query Members

query QueryMember($filter: MemberFilter) {
  queryMember(filter: $filter) {
    id
    source
  }
}

result:

{
  "errors": [
    {
      "message": "Non-nullable field 'nickname' (type String!) was not present in result from Dgraph.  GraphQL error propagation triggered.",
      "locations": [
        {
          "line": 9,
          "column": 5
        }
      ],
      "path": [
        "queryMember",
        0,
        "source"
      ]
    },
    {
      "message": "Non-nullable field 'nickname' (type String!) was not present in result from Dgraph.  GraphQL error propagation triggered.",
      "locations": [
        {
          "line": 9,
          "column": 5
        }
      ],
      "path": [
        "queryMember",
        1,
        "nickname"
      ]
    }
  ],
  "data": {
    "queryMember": [
      null,
      null
    ]
  },
  "extensions": {
    "touched_uids": 13,
    "tracing": {
      "version": 1,
      "startTime": "2023-04-03T23:58:15.1985333Z",
      "endTime": "2023-04-03T23:58:15.2292826Z",
      "duration": 30749300,
      "execution": {
        "resolvers": [
          {
            "path": [
              "queryMember"
            ],
            "parentType": "Query",
            "fieldName": "queryMember",
            "returnType": "[Member]",
            "startOffset": 647000,
            "duration": 29973700,
            "dgraph": [
              {
                "label": "query",
                "startOffset": 880400,
                "duration": 29730700
              }
            ]
          }
        ]
      }
    }
  }
}

Expected behavior and actual result.

Attempting to create a nested object via a deep update should fail/error if required/mandatory field values are not present in the mutation variables. Without this, it is easy to corrupt the data via user error.

Additional information

No response

benwoodward avatar Apr 04 '23 00:04 benwoodward

Thanks for filling the bug. I am able to reproduce it, could you also provide the value of $filter in the query if you still have it?

mangalaman93 avatar May 30 '23 02:05 mangalaman93

I am able to reproduce it, could you also provide the value of $filter in the query if you still have

I don't remember, however it was probably just a filter on id, as I tried to keep the example as minimal as possible, e.g.

    "filter": {
      "id": [
        "0x123abc"
      ]
    },

benwoodward avatar May 30 '23 04:05 benwoodward

This issue has been stale for 60 days and will be closed automatically in 7 days. Comment to keep it open.

github-actions[bot] avatar Jul 21 '24 14:07 github-actions[bot]