github.com/dgraph-io/dgraph@v1.2.8/graphql/resolve/add_mutation_test.yaml (about) 1 - 2 name: "Add mutation with variables" 3 gqlmutation: | 4 mutation addAuthor($auth: AddAuthorInput!) { 5 addAuthor(input: [$auth]) { 6 author { 7 name 8 } 9 } 10 } 11 gqlvariables: | 12 { "auth": 13 { "name": "A.N. Author", 14 "dob": "2000-01-01", 15 "posts": [] 16 } 17 } 18 explanation: "A uid and type should get injected and all data transformed to 19 underlying Dgraph edge names" 20 dgmutations: 21 - setjson: | 22 { "uid":"_:Author1", 23 "dgraph.type":["Author"], 24 "Author.name":"A.N. Author", 25 "Author.dob":"2000-01-01", 26 "Author.posts":[] 27 } 28 - 29 name: "Add multiple mutation with variables" 30 gqlmutation: | 31 mutation addAuthor($auth: [AddAuthorInput!]!) { 32 addAuthor(input: $auth) { 33 author { 34 name 35 } 36 } 37 } 38 gqlvariables: | 39 { "auth": [ 40 { "name": "A.N. Author" 41 }, 42 { "name": "Different Author" 43 } 44 ] 45 } 46 explanation: "A uid and type should get injected and all data transformed to 47 underlying Dgraph edge names" 48 dgmutations: 49 - setjson: | 50 { "uid":"_:Author1", 51 "dgraph.type":["Author"], 52 "Author.name":"A.N. Author" 53 } 54 - setjson: | 55 { "uid":"_:Author2", 56 "dgraph.type":["Author"], 57 "Author.name":"Different Author" 58 } 59 60 - 61 name: "Add Mutation with embedded value" 62 gqlmutation: | 63 mutation addAuthor { 64 addAuthor(input: [{ name: "A.N. Author", posts: []}]) { 65 author { 66 name 67 } 68 } 69 } 70 explanation: "The input should be used for the mutation, with a uid and type getting 71 injected and all data transformed to underlying Dgraph edge names" 72 dgmutations: 73 - setjson: | 74 { "uid":"_:Author1", 75 "dgraph.type":["Author"], 76 "Author.name":"A.N. Author", 77 "Author.posts":[] 78 } 79 80 - 81 name: "Add Mutation with mixed vars and embedded value" 82 gqlmutation: | 83 mutation addAuthor($name: String!) { 84 addAuthor(input: [{ name: $name, posts: []}]) { 85 author { 86 name 87 } 88 } 89 } 90 gqlvariables: | 91 { "name": "A.N. Author" } 92 explanation: "The input and variables should be used for the mutation, with a uid and type 93 getting injected and all data transformed to underlying Dgraph edge names" 94 dgmutations: 95 - setjson: | 96 { "uid":"_:Author1", 97 "dgraph.type":["Author"], 98 "Author.name":"A.N. Author", 99 "Author.posts":[] 100 } 101 102 - 103 name: "Add Multiple Mutations with embedded value" 104 gqlmutation: | 105 mutation addAuthor { 106 addAuthor(input: [{ name: "A.N. Author", posts: []}, {name: "Different Author", posts: []}]) { 107 author { 108 name 109 } 110 } 111 } 112 explanation: "The input should be used for the mutation, with a uid and type getting 113 injected and all data transformed to underlying Dgraph edge names" 114 dgmutations: 115 - setjson: | 116 { "uid":"_:Author1", 117 "dgraph.type":["Author"], 118 "Author.name":"A.N. Author", 119 "Author.posts":[] 120 } 121 - setjson: | 122 { "uid":"_:Author2", 123 "dgraph.type":["Author"], 124 "Author.name":"Different Author", 125 "Author.posts":[] 126 } 127 128 - 129 name: "Add mutation with reference" 130 gqlmutation: | 131 mutation addAuthor($auth: AddAuthorInput!) { 132 addAuthor(input: [$auth]) { 133 author { 134 name 135 } 136 } 137 } 138 gqlvariables: | 139 { "auth": 140 { "name": "A.N. Author", 141 "country": { "id": "0x123" }, 142 "posts": [] 143 } 144 } 145 explanation: "The reference to country should get transformed to 'uid' for the 146 Dgraph JSON mutation" 147 dgquery: |- 148 query { 149 Country2 as Country2(func: uid(0x123)) @filter(type(Country)) { 150 uid 151 } 152 } 153 dgmutations: 154 - setjson: | 155 { "uid":"_:Author1", 156 "dgraph.type":["Author"], 157 "Author.name":"A.N. Author", 158 "Author.country": { "uid": "0x123" }, 159 "Author.posts":[] 160 } 161 cond: "@if(eq(len(Country2), 1))" 162 163 - 164 name: "Add mutation with invalid reference" 165 gqlmutation: | 166 mutation addAuthor($auth: AddAuthorInput!) { 167 addAuthor(input: [$auth]) { 168 author { 169 name 170 } 171 } 172 } 173 gqlvariables: | 174 { "auth": 175 { "name": "A.N. Author", 176 "country": { "id": "HI!" }, 177 "posts": [] 178 } 179 } 180 explanation: "A reference must be a valid UID" 181 error: 182 { "message": 183 "failed to rewrite mutation payload because ID argument (HI!) was not able to be parsed" } 184 185 - 186 name: "Add mutation with inverse reference" 187 gqlmutation: | 188 mutation addPost($post: AddPostInput!) { 189 addPost(input: [$post]) { 190 post { 191 postID 192 } 193 } 194 } 195 gqlvariables: | 196 { "post": 197 { "title": "Exciting post", 198 "text": "A really good post", 199 "author": { "id": "0x2" } 200 } 201 } 202 explanation: "The reference to the author node should be transformed to include 203 a new 'posts' edge." 204 dgquery: |- 205 query { 206 Author2 as Author2(func: uid(0x2)) @filter(type(Author)) { 207 uid 208 } 209 } 210 dgmutations: 211 - setjson: | 212 { "uid" : "_:Post1", 213 "dgraph.type" : ["Post"], 214 "Post.title" : "Exciting post", 215 "Post.text" : "A really good post", 216 "Post.author": { 217 "uid" : "0x2", 218 "Author.posts" : [ { "uid": "_:Post1" } ] 219 } 220 } 221 cond: "@if(eq(len(Author2), 1))" 222 223 - 224 name: "Add mutation for a type that implements an interface" 225 gqlmutation: | 226 mutation addHuman($human: AddHumanInput!) { 227 addHuman(input: [$human]) { 228 human { 229 name 230 dob 231 female 232 } 233 } 234 } 235 gqlvariables: | 236 { "human": 237 { "name": "Bob", 238 "dob": "2000-01-01", 239 "female": true, 240 "ename": "employee no. 1" 241 } 242 } 243 explanation: "The mutation should get rewritten with correct edges from the interface." 244 dgmutations: 245 - setjson: | 246 { "uid" : "_:Human1", 247 "Character.name": "Bob", 248 "Employee.ename": "employee no. 1", 249 "Human.dob": "2000-01-01", 250 "Human.female": true, 251 "dgraph.type": ["Human", "Character", "Employee"] 252 } 253 254 - 255 name: "Add mutation using xid code" 256 gqlmutation: | 257 mutation addState($input: AddStateInput!) { 258 addState(input: [$input]) { 259 state { 260 name 261 } 262 } 263 } 264 gqlvariables: | 265 { "input": 266 { 267 "code": "nsw", 268 "name": "NSW", 269 "country": { "id": "0x12" } 270 } 271 } 272 explanation: "The add mutation should get rewritten into a Dgraph upsert mutation" 273 dgquery: |- 274 query { 275 State1 as State1(func: eq(State.code, "nsw")) @filter(type(State)) { 276 uid 277 } 278 Country2 as Country2(func: uid(0x12)) @filter(type(Country)) { 279 uid 280 } 281 } 282 dgmutations: 283 - setjson: | 284 { "uid" : "_:State1", 285 "dgraph.type": ["State"], 286 "State.name": "NSW", 287 "State.code": "nsw", 288 "State.country": { 289 "uid": "0x12", 290 "Country.states": [ { "uid": "_:State1" } ] 291 } 292 } 293 cond: "@if(eq(len(State1), 0) AND eq(len(Country2), 1))" 294 295 - 296 name: "Add mutation using code on type which also has an ID field" 297 gqlmutation: | 298 mutation addEditor($input: AddEditorInput!) { 299 addEditor(input: [$input]) { 300 editor { 301 name 302 } 303 } 304 } 305 gqlvariables: | 306 { "input": 307 { 308 "code": "editor", 309 "name": "A.N. Editor" 310 } 311 } 312 explanation: "The add mutation should get rewritten into a Dgraph upsert mutation" 313 dgquery: |- 314 query { 315 Editor1 as Editor1(func: eq(Editor.code, "editor")) @filter(type(Editor)) { 316 uid 317 } 318 } 319 dgmutations: 320 - setjson: | 321 { "uid" : "_:Editor1", 322 "dgraph.type": ["Editor"], 323 "Editor.name": "A.N. Editor", 324 "Editor.code": "editor" 325 } 326 cond: "@if(eq(len(Editor1), 0))" 327 328 - 329 name: "Deep add mutation" 330 gqlmutation: | 331 mutation addAuthor($author: AddAuthorInput!) { 332 addAuthor(input: [$author]) { 333 author { 334 id 335 } 336 } 337 } 338 gqlvariables: | 339 { "author": 340 { "name": "A.N. Author", 341 "dob": "2000-01-01", 342 "posts": [ 343 { 344 "title": "New post", 345 "text": "A really new post" 346 } 347 ] 348 } 349 } 350 dgmutations: 351 - setjson: | 352 { "uid" : "_:Author1", 353 "dgraph.type" : [ "Author" ], 354 "Author.name": "A.N. Author", 355 "Author.dob": "2000-01-01", 356 "Author.posts": [ 357 { 358 "uid": "_:Post2", 359 "dgraph.type" : [ "Post" ], 360 "Post.title" : "New post", 361 "Post.text" : "A really new post", 362 "Post.author": { 363 "uid" : "_:Author1" 364 } 365 } 366 ] 367 } 368 369 - 370 name: "Deep add multiple mutation" 371 gqlmutation: | 372 mutation addAuthor($author: [AddAuthorInput!]!) { 373 addAuthor(input: $author) { 374 author { 375 id 376 } 377 } 378 } 379 gqlvariables: | 380 { "author": [ 381 { "name": "A.N. Author", 382 "dob": "2000-01-01", 383 "posts": [ 384 { 385 "title": "New post", 386 "text": "A really new post" 387 } 388 ] 389 }, 390 { "name": "Different Author", 391 "dob": "2000-01-01", 392 "posts": [ 393 { 394 "title": "New New post", 395 "text": "A wonderful post" 396 } 397 ] 398 }] 399 } 400 dgmutations: 401 - setjson: | 402 { "uid" : "_:Author1", 403 "dgraph.type" : [ "Author" ], 404 "Author.name": "A.N. Author", 405 "Author.dob": "2000-01-01", 406 "Author.posts": [ 407 { 408 "uid": "_:Post2", 409 "dgraph.type" : [ "Post" ], 410 "Post.title" : "New post", 411 "Post.text" : "A really new post", 412 "Post.author": { 413 "uid" : "_:Author1" 414 } 415 } 416 ] 417 } 418 - setjson: | 419 { "uid" : "_:Author3", 420 "dgraph.type" : [ "Author" ], 421 "Author.name": "Different Author", 422 "Author.dob": "2000-01-01", 423 "Author.posts": [ 424 { 425 "uid": "_:Post4", 426 "dgraph.type" : [ "Post" ], 427 "Post.title" : "New New post", 428 "Post.text" : "A wonderful post", 429 "Post.author": { 430 "uid" : "_:Author3" 431 } 432 } 433 ] 434 } 435 436 - 437 name: "Deep add with existing" 438 gqlmutation: | 439 mutation addAuthor($author: AddAuthorInput!) { 440 addAuthor(input: [$author]) { 441 author { 442 id 443 } 444 } 445 } 446 gqlvariables: | 447 { "author": 448 { "name": "A.N. Author", 449 "dob": "2000-01-01", 450 "posts": [ 451 { 452 "title": "New post", 453 "text": "A really new post" 454 }, 455 { 456 "postID": "0x123", 457 "title": "Old post", 458 "text": "A really old post" 459 } 460 ] 461 } 462 } 463 dgquery: |- 464 query { 465 Post3 as Post3(func: uid(0x123)) @filter(type(Post)) { 466 uid 467 } 468 } 469 dgmutations: 470 - setjson: | 471 { "uid": "_:Author1", 472 "dgraph.type": [ "Author" ], 473 "Author.name": "A.N. Author", 474 "Author.dob": "2000-01-01", 475 "Author.posts": [ 476 { 477 "uid": "_:Post2", 478 "dgraph.type": [ "Post" ], 479 "Post.title": "New post", 480 "Post.text": "A really new post", 481 "Post.author": { 482 "uid": "_:Author1" 483 } 484 }, 485 { 486 "uid": "0x123", 487 "Post.author": { 488 "uid": "_:Author1" 489 } 490 } 491 ] 492 } 493 cond: "@if(eq(len(Post3), 1))" 494 495 - 496 name: "Deep add multiple with existing" 497 gqlmutation: | 498 mutation addAuthor($author: [AddAuthorInput!]!) { 499 addAuthor(input: $author) { 500 author { 501 id 502 } 503 } 504 } 505 gqlvariables: | 506 { "author": [ 507 { "name": "A.N. Author", 508 "dob": "2000-01-01", 509 "posts": [ 510 { 511 "title": "New post", 512 "text": "A really new post" 513 }, 514 { 515 "postID": "0x123", 516 "title": "Old post", 517 "text": "A really old post" 518 } 519 ] 520 }, 521 { "name": "Different Author", 522 "dob": "2000-01-01", 523 "posts": [ 524 { 525 "title": "New new post", 526 "text": "A wonderful post" 527 }, 528 { 529 "postID": "0x124", 530 "title": "Another Old post", 531 "text": "Another old post text" 532 } 533 ] 534 }] 535 } 536 dgquery: |- 537 query { 538 Post3 as Post3(func: uid(0x123)) @filter(type(Post)) { 539 uid 540 } 541 Post6 as Post6(func: uid(0x124)) @filter(type(Post)) { 542 uid 543 } 544 } 545 dgmutations: 546 - setjson: | 547 { "uid": "_:Author1", 548 "dgraph.type": [ "Author" ], 549 "Author.name": "A.N. Author", 550 "Author.dob": "2000-01-01", 551 "Author.posts": [ 552 { 553 "uid": "_:Post2", 554 "dgraph.type": [ "Post" ], 555 "Post.title": "New post", 556 "Post.text": "A really new post", 557 "Post.author": { 558 "uid": "_:Author1" 559 } 560 }, 561 { 562 "uid": "0x123", 563 "Post.author": { 564 "uid": "_:Author1" 565 } 566 } 567 ] 568 } 569 cond: "@if(eq(len(Post3), 1))" 570 - setjson: | 571 { "uid": "_:Author4", 572 "dgraph.type": [ "Author" ], 573 "Author.name": "Different Author", 574 "Author.dob": "2000-01-01", 575 "Author.posts": [ 576 { 577 "uid": "_:Post5", 578 "dgraph.type": [ "Post" ], 579 "Post.title": "New new post", 580 "Post.text": "A wonderful post", 581 "Post.author": { 582 "uid": "_:Author4" 583 } 584 }, 585 { 586 "uid": "0x124", 587 "Post.author": { 588 "uid": "_:Author4" 589 } 590 } 591 ] 592 } 593 cond: "@if(eq(len(Post6), 1))" 594 595 - 596 name: "Deep add with two existing" 597 gqlmutation: | 598 mutation addAuthor($author: AddAuthorInput!) { 599 addAuthor(input: [$author]) { 600 author { 601 id 602 } 603 } 604 } 605 gqlvariables: | 606 { "author": 607 { "name": "A.N. Author", 608 "dob": "2000-01-01", 609 "posts": [ 610 { 611 "postID": "0x123", 612 "title": "Old post", 613 "text": "A really old post" 614 }, 615 { 616 "postID": "0x456" 617 } 618 ] 619 } 620 } 621 dgquery: |- 622 query { 623 Post2 as Post2(func: uid(0x123)) @filter(type(Post)) { 624 uid 625 } 626 Post3 as Post3(func: uid(0x456)) @filter(type(Post)) { 627 uid 628 } 629 } 630 dgmutations: 631 - setjson: | 632 { "uid": "_:Author1", 633 "dgraph.type": [ "Author" ], 634 "Author.name": "A.N. Author", 635 "Author.dob": "2000-01-01", 636 "Author.posts": [ 637 { 638 "uid": "0x123", 639 "Post.author": { 640 "uid": "_:Author1" 641 } 642 }, 643 { 644 "uid": "0x456", 645 "Post.author": { 646 "uid": "_:Author1" 647 } 648 } 649 ] 650 } 651 cond: "@if(eq(len(Post2), 1) AND eq(len(Post3), 1))" 652 653 - 654 name: "Deep add with null" 655 gqlmutation: | 656 mutation addAuthor($author: AddAuthorInput!) { 657 addAuthor(input: [$author]) { 658 author { 659 id 660 } 661 } 662 } 663 gqlvariables: | 664 { "author": 665 { "name": "A.N. Author", 666 "dob": "2000-01-01", 667 "posts": [ 668 { 669 "postID": null, 670 "title": "New post", 671 "text": "A really new post" 672 } 673 ] 674 } 675 } 676 dgmutations: 677 - setjson: | 678 { "uid" : "_:Author1", 679 "dgraph.type" : [ "Author" ], 680 "Author.name": "A.N. Author", 681 "Author.dob": "2000-01-01", 682 "Author.posts": [ 683 { 684 "uid": "_:Post2", 685 "dgraph.type" : [ "Post" ], 686 "Post.title" : "New post", 687 "Post.text" : "A really new post", 688 "Post.author": { 689 "uid" : "_:Author1" 690 } 691 } 692 ] 693 } 694 695 - 696 name: "Add three deep" 697 gqlmutation: | 698 mutation addAuthor($author: AddAuthorInput!) { 699 addAuthor(input: [$author]) { 700 author { 701 id 702 } 703 } 704 } 705 gqlvariables: | 706 { "author": 707 { "name": "A.N. Author", 708 "dob": "2000-01-01", 709 "posts": [ 710 { 711 "title": "Exciting post", 712 "text": "A really good post", 713 "category": { 714 "name": "New Category" 715 } 716 } 717 ] 718 } 719 } 720 dgmutations: 721 - setjson: | 722 { "uid": "_:Author1", 723 "dgraph.type": [ "Author" ], 724 "Author.name": "A.N. Author", 725 "Author.dob": "2000-01-01", 726 "Author.posts": [ 727 { 728 "uid": "_:Post2", 729 "dgraph.type": [ "Post" ], 730 "Post.title": "Exciting post", 731 "Post.text": "A really good post", 732 "Post.author": { 733 "uid": "_:Author1" 734 }, 735 "Post.category": { 736 "uid": "_:Category3", 737 "dgraph.type": [ "Category" ], 738 "Category.name": "New Category", 739 "Category.posts": [ 740 { "uid": "_:Post2" } 741 ] 742 } 743 } 744 ] 745 } 746 747 - 748 name: "Add mutation with deep xid choices" 749 gqlmutation: | 750 mutation addCountry($input: AddCountryInput!) { 751 addCountry(input: [$input]) { 752 country { 753 name 754 } 755 } 756 } 757 gqlvariables: | 758 { "input": 759 { 760 "name": "Dgraph Land", 761 "states": [ { 762 "code": "dg", 763 "name": "Dgraph" 764 } ] 765 } 766 } 767 explanation: "The add mutation has two options depending on if dg exists" 768 dgquery: |- 769 query { 770 State2 as State2(func: eq(State.code, "dg")) @filter(type(State)) { 771 uid 772 } 773 } 774 dgmutations: 775 - setjson: | 776 { 777 "uid": "_:Country1", 778 "dgraph.type": ["Country"], 779 "Country.name": "Dgraph Land", 780 "Country.states": [ { 781 "uid": "_:State2", 782 "dgraph.type": ["State"], 783 "State.code": "dg", 784 "State.name": "Dgraph", 785 "State.country": { 786 "uid": "_:Country1" 787 } 788 } ] 789 } 790 cond: "@if(eq(len(State2), 0))" 791 - setjson: | 792 { 793 "uid": "_:Country1", 794 "dgraph.type": ["Country"], 795 "Country.name": "Dgraph Land", 796 "Country.states": [ { 797 "uid": "uid(State2)", 798 "State.country": { 799 "uid": "_:Country1" 800 } 801 } ] 802 } 803 cond: "@if(eq(len(State2), 1))" 804 805 - 806 name: "Add mutation with deep xid that must be reference" 807 gqlmutation: | 808 mutation addCountry($input: AddCountryInput!) { 809 addCountry(input: [$input]) { 810 country { 811 name 812 } 813 } 814 } 815 gqlvariables: | 816 { "input": 817 { 818 "name": "Dgraph Land", 819 "states": [ { 820 "code": "dg" 821 } ] 822 } 823 } 824 explanation: "The add mutation has only one option because the state isn't a valid create 825 because it's missing required field name" 826 dgquery: |- 827 query { 828 State2 as State2(func: eq(State.code, "dg")) @filter(type(State)) { 829 uid 830 } 831 } 832 dgmutations: 833 - setjson: | 834 { 835 "uid": "_:Country1", 836 "dgraph.type": ["Country"], 837 "Country.name": "Dgraph Land", 838 "Country.states": [ { 839 "uid": "uid(State2)", 840 "State.country": { 841 "uid": "_:Country1" 842 } 843 } ] 844 } 845 cond: "@if(eq(len(State2), 1))"