dgraph icon indicating copy to clipboard operation
dgraph copied to clipboard

Support GraphQL variables in mutations

Open F21 opened this issue 5 years ago • 3 comments

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.

F21 avatar Jan 18 '20 23:01 F21

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

miko avatar Mar 05 '20 12:03 miko

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.

MichaelJCompton avatar Mar 11 '20 23:03 MichaelJCompton

Github issues have been deprecated. This issue has been moved to discuss. You can follow the conversation there and also subscribe to updates by changing your notification preferences.

drawing

minhaj-shakeel avatar Jul 20 '20 19:07 minhaj-shakeel