github.com/dgraph-io/dgraph@v1.2.8/graphql/resolve/update_mutation_test.yaml (about)

     1  -
     2    name: "Update set mutation with variables"
     3    gqlmutation: |
     4      mutation updatePost($patch: UpdatePostInput!) {
     5        updatePost(input: $patch) {
     6          post {
     7            postID
     8          }
     9        }
    10      }
    11    gqlvariables: |
    12      { "patch":
    13        { "filter": {
    14            "postID": ["0x123", "0x124"]
    15          },
    16          "set": {
    17            "text": "updated text"
    18          }
    19        }
    20      }
    21    explanation: "The update patch should get rewritten into the Dgraph set mutation"
    22    dgmutations:
    23      - setjson: |
    24          { "uid" : "uid(x)",
    25            "Post.text": "updated text"
    26          }
    27        cond: "@if(gt(len(x), 0))"
    28    dgquery: |-
    29      query {
    30        x as updatePost(func: type(Post)) @filter(uid(0x123, 0x124)) {
    31          uid
    32        }
    33      }
    34  
    35  -
    36    name: "Update remove mutation with variables and value"
    37    gqlmutation: |
    38      mutation updatePost($patch: UpdatePostInput!) {
    39        updatePost(input: $patch) {
    40          post {
    41            postID
    42          }
    43        }
    44      }
    45    gqlvariables: |
    46      { "patch":
    47        { "filter": {
    48            "postID": ["0x123", "0x124"]
    49          },
    50          "remove": {
    51            "text": "delete this text"
    52          }
    53        }
    54      }
    55    explanation: "The update patch should get rewritten into the Dgraph delete mutation"
    56    dgmutations:
    57      - deletejson: |
    58          { "uid" : "uid(x)",
    59            "Post.text": "delete this text"
    60          }
    61        cond: "@if(gt(len(x), 0))"
    62    dgquery: |-
    63      query {
    64        x as updatePost(func: type(Post)) @filter(uid(0x123, 0x124)) {
    65          uid
    66        }
    67      }
    68  
    69  -
    70    name: "Update delete mutation with variables and null"
    71    gqlmutation: |
    72      mutation updatePost($patch: UpdatePostInput!) {
    73        updatePost(input: $patch) {
    74          post {
    75            postID
    76          }
    77        }
    78      }
    79    gqlvariables: |
    80      { "patch":
    81        { "filter": {
    82            "postID": ["0x123", "0x124"]
    83          },
    84          "remove": {
    85            "text": null
    86          }
    87        }
    88      }
    89    explanation: "The update patch should get rewritten into the Dgraph mutation"
    90    dgmutations:
    91      - deletejson: |
    92          { "uid" : "uid(x)",
    93            "Post.text": null
    94          }
    95        cond: "@if(gt(len(x), 0))"
    96    dgquery: |-
    97      query {
    98        x as updatePost(func: type(Post)) @filter(uid(0x123, 0x124)) {
    99          uid
   100        }
   101      }
   102  
   103  -
   104    name: "Update mutation for a type that implements an interface"
   105    gqlmutation: |
   106      mutation updateHuman($patch: UpdateHumanInput!) {
   107        updateHuman(input: $patch) {
   108          human {
   109            name
   110            dob
   111            female
   112          }
   113        }
   114      }
   115    gqlvariables: |
   116      { "patch":
   117        {
   118          "filter": {
   119            "id": ["0x123"]
   120          },
   121          "set": { "name": "Bob",
   122            "dob": "2000-01-01",
   123            "female": true,
   124            "ename": "employee no. 1"
   125          }
   126        }
   127      }
   128    explanation: "The mutation should get rewritten with correct edges from the interface."
   129    dgmutations:
   130      - setjson: |
   131          { "uid" : "uid(x)",
   132            "Character.name": "Bob",
   133            "Employee.ename": "employee no. 1",
   134            "Human.dob": "2000-01-01",
   135            "Human.female": true
   136          }
   137        cond: "@if(gt(len(x), 0))"
   138    dgquery: |-
   139      query {
   140        x as updateHuman(func: type(Human)) @filter(uid(0x123)) {
   141          uid
   142        }
   143      }
   144  
   145  -
   146    name: "Update mutation for an interface"
   147    gqlmutation: |-
   148      mutation {
   149        updateCharacter(input: {filter: { id: ["0x123"] }, set: {name:"Bob"}}) {
   150          character {
   151            id
   152            name
   153          }
   154        }
   155      }
   156    explanation: "The mutation should get rewritten with correct edges from the interface."
   157    dgmutations:
   158      - setjson: |
   159          { "uid" : "uid(x)",
   160            "Character.name": "Bob"
   161          }
   162        cond: "@if(gt(len(x), 0))"
   163    dgquery: |-
   164      query {
   165        x as updateCharacter(func: type(Character)) @filter(uid(0x123)) {
   166          uid
   167        }
   168      }
   169  
   170  -
   171    name: "Update mutation using filters"
   172    gqlmutation: |
   173      mutation updatePost($patch: UpdatePostInput!) {
   174        updatePost(input: $patch) {
   175          post {
   176            postID
   177          }
   178        }
   179      }
   180    gqlvariables: |
   181      { "patch":
   182        { "filter": {
   183            "tags": { "eq": "foo"}
   184          },
   185          "set": {
   186            "text": "updated text"
   187          }
   188        }
   189      }
   190    explanation: "The update patch should get rewritten into the Dgraph mutation"
   191    dgmutations:
   192      - setjson: |
   193          { "uid" : "uid(x)",
   194            "Post.text": "updated text"
   195          }
   196        cond: "@if(gt(len(x), 0))"
   197    dgquery: |-
   198      query {
   199        x as updatePost(func: type(Post)) @filter(eq(Post.tags, "foo")) {
   200          uid
   201        }
   202      }
   203  
   204  -
   205    name: "Update mutation using code"
   206    gqlmutation: |
   207      mutation updateState($patch: UpdateStateInput!) {
   208        updateState(input: $patch) {
   209          state {
   210            name
   211          }
   212        }
   213      }
   214    gqlvariables: |
   215      { "patch":
   216        { "filter": {
   217            "code": { "eq": "nsw" }
   218          },
   219          "set": {
   220            "name": "nsw"
   221          }
   222        }
   223      }
   224    explanation: "The update mutation should get rewritten into a Dgraph upsert mutation"
   225    dgmutations:
   226      - setjson: |
   227          { "uid" : "uid(x)",
   228            "State.name": "nsw"
   229          }
   230        cond: "@if(gt(len(x), 0))"
   231    dgquery: |-
   232      query {
   233        x as updateState(func: type(State)) @filter(eq(State.code, "nsw")) {
   234          uid
   235        }
   236      }
   237  
   238  -
   239    name: "Update mutation using code on type which also has an ID field"
   240    gqlmutation: |
   241      mutation updateEditor($patch: UpdateEditorInput!) {
   242        updateEditor(input: $patch) {
   243          editor {
   244            name
   245          }
   246        }
   247      }
   248    gqlvariables: |
   249      { "patch":
   250        { "filter": {
   251            "code": { "eq": "editor" },
   252            "id": [ "0x1", "0x2" ]
   253          },
   254          "set": {
   255            "name": "A.N. Editor"
   256          }
   257        }
   258      }
   259    explanation: "The update mutation should get rewritten into a Dgraph upsert mutation"
   260    dgmutations:
   261      - setjson: |
   262          { "uid" : "uid(x)",
   263            "Editor.name": "A.N. Editor"
   264          }
   265        cond: "@if(gt(len(x), 0))"
   266    dgquery: |-
   267      query {
   268        x as updateEditor(func: type(Editor)) @filter((eq(Editor.code, "editor") AND uid(0x1, 0x2))) {
   269          uid
   270        }
   271      }
   272  
   273  -
   274    name: "Update add reference"
   275    gqlmutation: |
   276      mutation updateAuthor($patch: UpdateAuthorInput!) {
   277        updateAuthor(input: $patch) {
   278          author {
   279            id
   280          }
   281        }
   282      }
   283    gqlvariables: |
   284      { "patch":
   285        { "filter": {
   286            "id": ["0x123"]
   287          },
   288          "set": {
   289            "posts": [ { "postID": "0x456" } ]
   290          }
   291        }
   292      }
   293    dgmutations:
   294      - setjson: |
   295          { "uid" : "uid(x)",
   296            "Author.posts": [
   297              {
   298                "uid": "0x456",
   299                "Post.author": { "uid": "uid(x)" }
   300              }
   301            ]
   302          }
   303        cond: "@if(eq(len(Post2), 1) AND gt(len(x), 0))"
   304    dgquery: |-
   305      query {
   306        x as updateAuthor(func: type(Author)) @filter(uid(0x123)) {
   307          uid
   308        }
   309        Post2 as Post2(func: uid(0x456)) @filter(type(Post)) {
   310          uid
   311        }
   312      }
   313  
   314  -
   315    name: "Update remove reference"
   316    gqlmutation: |
   317      mutation updateAuthor($patch: UpdateAuthorInput!) {
   318        updateAuthor(input: $patch) {
   319          author {
   320            id
   321          }
   322        }
   323      }
   324    gqlvariables: |
   325      { "patch":
   326        { "filter": {
   327            "id": ["0x123"]
   328          },
   329          "remove": {
   330            "posts": [ { "postID": "0x456" } ]
   331          }
   332        }
   333      }
   334    dgmutations:
   335      - deletejson: |
   336          { "uid" : "uid(x)",
   337            "Author.posts": [
   338              {
   339                "uid": "0x456",
   340                "Post.author": { "uid": "uid(x)" }
   341              }
   342            ]
   343          }
   344        cond: "@if(eq(len(Post2), 1) AND gt(len(x), 0))"
   345    dgquery: |-
   346      query {
   347        x as updateAuthor(func: type(Author)) @filter(uid(0x123)) {
   348          uid
   349        }
   350        Post2 as Post2(func: uid(0x456)) @filter(type(Post)) {
   351          uid
   352        }
   353      }
   354  
   355  -
   356    name: "Update add and remove together"
   357    gqlmutation: |
   358      mutation updateAuthor($patch: UpdateAuthorInput!) {
   359        updateAuthor(input: $patch) {
   360          author {
   361            id
   362          }
   363        }
   364      }
   365    gqlvariables: |
   366      { "patch":
   367        { "filter": {
   368            "id": ["0x123"]
   369          },
   370          "set": {
   371            "posts": [ { "postID": "0x456" } ]
   372          },
   373          "remove": {
   374            "posts": [ { "postID": "0x789" } ]
   375          }
   376        }
   377      }
   378    dgmutations:
   379      - setjson: |
   380          { "uid" : "uid(x)",
   381            "Author.posts": [
   382              {
   383                "uid": "0x456",
   384                "Post.author": { "uid": "uid(x)" }
   385              }
   386            ]
   387          }
   388        cond: "@if(eq(len(Post2), 1) AND gt(len(x), 0))"
   389      - deletejson: |
   390          { "uid" : "uid(x)",
   391            "Author.posts": [
   392              {
   393                "uid": "0x789",
   394                "Post.author": { "uid": "uid(x)" }
   395              }
   396            ]
   397          }
   398        cond: "@if(eq(len(Post4), 1) AND gt(len(x), 0))"
   399    dgquery: |-
   400      query {
   401        x as updateAuthor(func: type(Author)) @filter(uid(0x123)) {
   402          uid
   403        }
   404        Post2 as Post2(func: uid(0x456)) @filter(type(Post)) {
   405          uid
   406        }
   407        Post4 as Post4(func: uid(0x789)) @filter(type(Post)) {
   408          uid
   409        }
   410      }
   411  
   412  -
   413    name: "Deep updates don't alter linked objects"
   414    gqlmutation: |
   415      mutation updateAuthor($patch: UpdateAuthorInput!) {
   416        updateAuthor(input: $patch) {
   417          author {
   418            id
   419          }
   420        }
   421      }
   422    gqlvariables: |
   423      { "patch":
   424        { "filter": {
   425            "id": ["0x123"]
   426          },
   427          "set": {
   428            "posts": [ {
   429              "postID": "0x456",
   430              "title": "A new title",
   431              "text": "Some edited text"
   432            } ]
   433          }
   434        }
   435      }
   436    explanation: "updateAuthor doesn't update posts"
   437    dgmutations:
   438      - setjson: |
   439          { "uid" : "uid(x)",
   440            "Author.posts": [
   441              {
   442                "uid": "0x456",
   443                "Post.author": { "uid": "uid(x)" }
   444              }
   445            ]
   446          }
   447        cond: "@if(eq(len(Post2), 1) AND gt(len(x), 0))"
   448    dgquery: |-
   449      query {
   450        x as updateAuthor(func: type(Author)) @filter(uid(0x123)) {
   451          uid
   452        }
   453        Post2 as Post2(func: uid(0x456)) @filter(type(Post)) {
   454          uid
   455        }
   456      }
   457  
   458  -
   459    name: "Deep update"
   460    gqlmutation: |
   461      mutation updateAuthor($patch: UpdateAuthorInput!) {
   462        updateAuthor(input: $patch) {
   463          author {
   464            id
   465          }
   466        }
   467      }
   468    gqlvariables: |
   469      { "patch":
   470        { "filter": {
   471            "id": ["0x123"]
   472          },
   473          "set": {
   474            "country": {
   475              "name": "New Country"
   476            }
   477          }
   478        }
   479      }
   480    explanation: "The update creates a new country"
   481    dgmutations:
   482      - setjson: |
   483          { "uid" : "uid(x)",
   484            "Author.country": {
   485              "uid": "_:Country2",
   486              "dgraph.type": ["Country"],
   487              "Country.name": "New Country"
   488            }
   489          }
   490        cond: "@if(gt(len(x), 0))"
   491    dgquery: |-
   492      query {
   493        x as updateAuthor(func: type(Author)) @filter(uid(0x123)) {
   494          uid
   495        }
   496      }
   497  
   498  -
   499    name: "Deep xid create options"
   500    gqlmutation: |
   501      mutation updateAuthor($patch: UpdateAuthorInput!) {
   502        updateAuthor(input: $patch) {
   503          author {
   504            id
   505          }
   506        }
   507      }
   508    gqlvariables: |
   509      { "patch":
   510        { "filter": {
   511            "id": ["0x123"]
   512          },
   513          "set": {
   514            "country": {
   515              "name": "New Country",
   516              "states": [ {
   517                "code": "dg",
   518                "name": "Dgraph"
   519              } ]
   520            }
   521          }
   522        }
   523      }
   524    explanation: "The update has a choice of linking to new or existing state"
   525    dgmutations:
   526      - setjson: |
   527          { "uid" : "uid(x)",
   528            "Author.country": {
   529              "uid": "_:Country2",
   530              "dgraph.type": ["Country"],
   531              "Country.name": "New Country",
   532              "Country.states": [ {
   533                "uid": "_:State3",
   534                "dgraph.type": ["State"],
   535                "State.code": "dg",
   536                "State.name": "Dgraph",
   537                "State.country": {
   538                  "uid": "_:Country2"
   539                }
   540              } ]
   541            }
   542          }
   543        cond: "@if(eq(len(State3), 0) AND gt(len(x), 0))"
   544      - setjson: |
   545          { "uid" : "uid(x)",
   546            "Author.country": {
   547              "uid": "_:Country2",
   548              "dgraph.type": ["Country"],
   549              "Country.name": "New Country",
   550              "Country.states": [ {
   551                "uid": "uid(State3)",
   552                "State.country": {
   553                  "uid": "_:Country2"
   554                }
   555              } ]
   556            }
   557          }
   558        cond: "@if(eq(len(State3), 1) AND gt(len(x), 0))"
   559    dgquery: |-
   560      query {
   561        x as updateAuthor(func: type(Author)) @filter(uid(0x123)) {
   562          uid
   563        }
   564        State3 as State3(func: eq(State.code, "dg")) @filter(type(State)) {
   565          uid
   566        }
   567      }
   568  
   569  -
   570    name: "Deep xid link only"
   571    gqlmutation: |
   572      mutation updateAuthor($patch: UpdateAuthorInput!) {
   573        updateAuthor(input: $patch) {
   574          author {
   575            id
   576          }
   577        }
   578      }
   579    gqlvariables: |
   580      { "patch":
   581        { "filter": {
   582            "id": ["0x123"]
   583          },
   584          "set": {
   585            "country": {
   586              "name": "New Country",
   587              "states": [ {
   588                "code": "dg"
   589              } ]
   590            }
   591          }
   592        }
   593      }
   594    explanation: "The update must link to the existing state"
   595    dgmutations:
   596      - setjson: |
   597          { "uid" : "uid(x)",
   598            "Author.country": {
   599              "uid": "_:Country2",
   600              "dgraph.type": ["Country"],
   601              "Country.name": "New Country",
   602              "Country.states": [ {
   603                "uid": "uid(State3)",
   604                "State.country": {
   605                  "uid": "_:Country2"
   606                }
   607              } ]
   608            }
   609          }
   610        cond: "@if(eq(len(State3), 1) AND gt(len(x), 0))"
   611    dgquery: |-
   612      query {
   613        x as updateAuthor(func: type(Author)) @filter(uid(0x123)) {
   614          uid
   615        }
   616        State3 as State3(func: eq(State.code, "dg")) @filter(type(State)) {
   617          uid
   618        }
   619      }