Skip to content

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

Open
@benwoodward

Description

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

Metadata

Assignees

No one assigned

    Labels

    area/graphqlIssues related to GraphQL support on Dgraph.communityIssue or PR created by the community.kind/bugSomething is broken.status/acceptedWe accept to investigate/work on it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions