Exception when adding data using GraphQL

My GraphQL Schema is as follows:

type Change_log {
	id:Int @id
    op_user_no: Int64 @search(by: [int64])
    op_time: DateTime @search(by: [hour])
    op_content_text: String @search(by: [fulltext])
    ref_log_id: [change_log] @hasInverse(field: ref_log_id)
    op_type: Int
}

I use GraphQL to add data, GraphQL is as follows:

mutation {
     addChange_log(input: [{
                 id: 1
                 op_user_no: 123
                 op_time: "2022-05-26T16:05:45Z"
                 op_content_text: "test"
                 op_type: 1
                 ref_log_id: [{
                         id: 0
                     }
                 ]
             }
         ], upsert: true) {
         numUids
     }
 }

All data in Type is associated with the data whose id is 0.

When I use multi-threading to execute GraphQL on the data, some data can be inserted normally, and some data are inserted abnormally. The exception information is as follows:

{
    "errors": [{
            "message": "mutation addChange_log failed because Dgraph execution failed because Input for predicate \"addChange_log.ref_log_id\" of type scalar is uid. Edge: entity:84293879 attr:\"\\000\\000\\000\\000\\000\\000\\000\\000addChange_log.ref_log_id\" value_type:UID value_id:84293878 ",
            "locations": [{
                    "line": 2,
                    "column": 2
                }
            ],
            "path": ["addChange_log"]
        }
    ],
    "data": {
        "addChange_log": null
    },
    "extensions": {
        "touched_uids": 2,
        "tracing": {
            "version": 1,
            "startTime": "2022-05-26T08:51:04.351495399Z",
            "endTime": "2022-05-26T08:51:04.35609656Z",
            "duration": 4601172,
            "execution": {
                "resolvers": [{
                        "path": ["addChange_log"],
                        "parentType": "Mutation",
                        "fieldName": "addChange_log",
                        "returnType": "AddChange_logPayload",
                        "startOffset": 186319,
                        "duration": 4406580,
                        "dgraph": [{
                                "label": "preMutationQuery",
                                "startOffset": 251187,
                                "duration": 1667669
                            }, {
                                "label": "mutation",
                                "startOffset": 2048529,
                                "duration": 0
                            }, {
                                "label": "query",
                                "startOffset": 0,
                                "duration": 0
                            }
                        ]
                    }
                ]
            }
        }
    }
}

But I took out the GraphQL that reported the error and executed it in Postman, and it was normal.

I don’t know why this happens, I hope to get everyone’s help, thank you very much.

1 Like

hi i have 0 knowledge about that one
the graphql layer is afaik not completely perfect, maybe that’s why “advanced stuff” doesn;t work
i highly recommend checking out the docs https://dgraph.io/docs/graphql/

There are 2 issues in your query:

  1. You don’t need to add the id of the new Change_log, as it will be automatically created.
  2. Id’s are uid's, which means that in the GraphQL it should be passed as string, because they have different format. Ex. Instead of 0, the correct pattern would be "0x0"
1 Like

Hi @Juri
Thank you very much for your reply,i have resolved the issue.

1 Like

Hi @ricglz
Thank you very much for your reply,the Id field in Change_log is only a unique field, not Uid. It is Uid only when the field is defined as ID. I set upsert: true here, then automatically according to whether the value of the Id field exists, if it does not exist, it will be added. then update.

1 Like

Hi can you tell us how you resolved the issue? One day someone will have the same problem and will be happy if you wrote how you solved the issue :smiley:

Hi @Juri
There are three Alpha nodes in the cluster I deployed. At first, I randomly select an Alpha node to initiate the request, and the above problem occurs, but when I use only one Alpha node, everything works fine,
I also can’t understand the reason.

1 Like