dgraph-client icon indicating copy to clipboard operation
dgraph-client copied to clipboard

mutation query error

Open gleba opened this issue 7 years ago • 3 comments

The requests with mutations as mutation {set{<9963693899913877966> <state> "4".}} returned empty and with an error But make changes.

Output log:

response:  { name: 'ship', state: 3, _uid_: '9963693899913877966' }
mutation query:  mutation {set{<9963693899913877966> <state> "4".}}
mutation query response:  undefined
query:  query { me(id:9963693899913877966) { name, state, _uid_ } }
TypeError: Cannot read property 'uid' of undefined
    at Object.nodeToObject (...\dgraph\converter.js:85:13)
    at run.then.response (...\dgraph\index.js:42:32)
query response:  { me: { _uid_: '9963693899913877966', name: 'ship', state: 4 } }

source code:

    let data: any = {name: "ship", state: 3}
    let respone1: any = await client.set(data)
    console.log("response: ", respone1)

    let mq = `mutation {set{<${data._uid_}> <state> "4".}}`
    console.log("mutation query: ", mq)
    let respone2 = await client.query(mq).catch(console.error)
        .catch(x => console.warn(x))
    console.log("mutation query response: ", respone2)

    let q2 = `query { me(id:${respone1._uid_}) { name, state, _uid_ } }`
    console.log("query: ", q2)
    let respone4 = await client.query(q2)
    console.log("query response: ", respone4)

gleba avatar May 12 '17 10:05 gleba

Hi @gleba,

Mutation queries are currently not supported, as they send another response as queries.

But for now, you can just ignore the error, or modify an existing object by:

await client.set( {_uid_: data._uid_, state: 4} )

Best, Paul

reicheltp avatar May 12 '17 10:05 reicheltp

@gleba What's your usecase to send raw mutation queries? Actuall, the api is designed to be a high level api wrapper around the raw gRPC. Therefore a query is scoped to the right object and on set the uid's are reassigned automatically.

If you like to send some special raw gRPC request, you can do this the following way:

var request = new DgraphClient.Request()
request.query = 'mutation {set{<9963693899913877966> <state> "4".}}'
var response = await client.run(request) 

The response is a structured like this proto https://github.com/dgraph-io/dgraph/blob/release/v0.7.5/protos/graphp/graphresponse.proto#L97-L102

Nevertheless, this is all WIP and designed around my usecases, so if you have some ideas to extend the API, I am curious to hear them.

reicheltp avatar May 12 '17 10:05 reicheltp

@reicheltp Thank you. With this understanding of the current API is enough. My case in research progress.

gleba avatar May 12 '17 11:05 gleba