dgraph-io / dgraph

The high-performance database for modern applications
https://dgraph.io
Other
20.44k stars 1.5k forks source link

Support DQL variables in mutations #4615

Closed F21 closed 3 months ago

F21 commented 4 years ago

Experience Report

What you wanted to do

I want to perform a mutation in an upsert block using user-provided data safely.

What you actually did

upsert ($name: string){
      query {
        var(func: eq(xid, "http://schema.org/Person")) {
          Type as uid
        }
        var(func: eq(<http://schema.org/name>, "Robin Wright")) {
          Person as uid
        }
      }
      mutation {
          set {
           uid(Person) <xid> "https://www.themoviedb.org/person/32-robin-wright" .
           uid(Person) <http://schema.org/type> uid(Type) .
           uid(Person) <http://schema.org/name> $name .
           uid(Person) <dgraph.type> "Person" .
          }
      }
    }

Why that wasn't great, with examples

GraphQL variables are not supported in mutations, so it's impossible to safely mutate user-provided data without error-prone validation.

Any external references to support your case

None at the moment.

miko commented 4 years ago

I also support this request. The rationale is the same as for GraphQL variables in queries: https://docs.dgraph.io/query-language/#graphql-variables

MichaelJCompton commented 4 years ago

This looks like a reasonable feature request.

I'm tagging it as accepted, which means it will get into our backlog of features to consider.

If we decide to implement it, we'll post an update here.

github-actions[bot] commented 3 months ago

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