github.com/dgraph-io/dgraph@v1.2.8/graphql/resolve/resolver_error_test.yaml (about) 1 - 2 name: "Strip Dgraph result list for non-list query result" 3 gqlquery: | 4 query { 5 getAuthor(id: "0x1") { 6 name 7 } 8 } 9 explanation: "Dgraph always returns a query result as a list. That needs to be 10 fixed for queries with non-list result types." 11 response: | 12 { "getAuthor": [ { "uid": "0x1", "name": "A.N. Author" } ] } 13 expected: | 14 { "getAuthor": { "name": "A.N. Author" } } 15 16 - 17 name: "Empty query result becomes null" 18 gqlquery: | 19 query { 20 getAuthor(id: "0x1") { 21 name 22 } 23 } 24 explanation: "If Dgraph finds no results for a query, and the GraphQL 25 type is nullable, we should set the result to null." 26 response: | 27 { } 28 expected: | 29 { "getAuthor": null } 30 31 - 32 name: "Root level handled correctly if just uid when non-nullable missing" 33 gqlquery: | 34 query { 35 getAuthor(id: "0x1") { 36 name 37 } 38 } 39 explanation: "GraphQL error propagation causes an error on a non-nullable field 40 (like name: String!) to propagate to the parent object." 41 response: | 42 { "getAuthor": [ { "uid": "0x1" } ] } 43 expected: | 44 { "getAuthor": null } 45 errors: 46 [ { 47 "message": "Non-nullable field 'name' (type String!) was not present in 48 result from Dgraph. GraphQL error propagation triggered." , 49 "path": [ "getAuthor", "name" ], 50 "locations": [ { "line": 3, "column": 5 } ] } ] 51 52 - 53 name: "Multiple nullable query results becomes nulls (with alias)" 54 gqlquery: | 55 query { 56 getAuthor(id: "0x1") { 57 name 58 } 59 auth : getAuthor(id: "0x1") { 60 name 61 } 62 } 63 explanation: "If Dgraph finds no results for a query, and the GraphQL 64 type is nullable, we should set the result to null." 65 response: | 66 { } 67 expected: | 68 { "getAuthor": null, "auth": null } 69 70 - 71 name: "Multiple query results with a nullable becomes null" 72 gqlquery: | 73 query { 74 getAuthor(id: "0x1") { 75 name 76 } 77 auth : getAuthor(id: "0x1") { 78 name 79 } 80 } 81 explanation: "Even if some queries result in null, we should return all the 82 results we got." 83 response: | 84 { "getAuthor": [ { "uid": "0x1", "name": "A.N. Author" } ] } 85 expected: | 86 { "getAuthor": { "name": "A.N. Author" }, "auth": null } 87 88 - 89 name: "Missing nullable field becomes null" 90 gqlquery: | 91 query { 92 getAuthor(id: "0x1") { 93 name 94 dob 95 } 96 } 97 explanation: "When a field that's nullable (like dob: DateTime) is missing 98 in the Dgraph result, it should be added as null to the GraphQL result." 99 response: | 100 { "getAuthor": [ { "uid": "0x1", "name": "A.N. Author" } ] } 101 expected: | 102 { "getAuthor": { "name": "A.N. Author", "dob": null } } 103 104 - 105 name: "Root level handled correctly if just uid when nullable missing" 106 gqlquery: | 107 query { 108 getAuthor(id: "0x1") { 109 dob 110 } 111 } 112 explanation: "GraphQL error propagation causes an error on a non-nullable field 113 (like name: String!) to propagate to the parent object." 114 response: | 115 { "getAuthor": [ { "uid": "0x1" } ] } 116 expected: | 117 { "getAuthor": { "dob": null } } 118 119 - 120 name: "Missing nullable field becomes null (aliased)" 121 gqlquery: | 122 query { 123 getAuthor(id: "0x1") { 124 name 125 birthday : dob 126 } 127 } 128 explanation: "When a field that's nullable (like dob: DateTime) is missing 129 in the Dgraph result, it should be added as null to the GraphQL result." 130 response: | 131 { "getAuthor": [ { "uid": "0x1", "name": "A.N. Author" } ] } 132 expected: | 133 { "getAuthor": { "name": "A.N. Author", "birthday": null } } 134 135 - 136 name: "Missing nullable becomes null (deep)" 137 gqlquery: | 138 query { 139 getAuthor(id: "0x1") { 140 name 141 postsRequired { 142 title 143 text 144 } 145 } 146 } 147 explanation: "When a field that's nullable (like text: String) is missing 148 in the Dgraph result, it should be added as null to the GraphQL result." 149 response: | 150 { "getAuthor": [ 151 { "uid": "0x1", 152 "name": "A.N. Author", 153 "postsRequired": [ { "uid": "0x2", "title": "A Title" } ] } 154 ] } 155 expected: | 156 { "getAuthor": 157 { "name": "A.N. Author", 158 "postsRequired": [ { "title": "A Title", "text": null } ] } 159 } 160 161 - 162 name: "Missing required list becomes []" 163 gqlquery: | 164 query { 165 getAuthor(id: "0x1") { 166 name 167 postsRequired { 168 title 169 } 170 } 171 } 172 explanation: "When a field of any list type is missing in the result, 173 it should be added as an empty list [], not null" 174 response: | 175 { "getAuthor": [ { "uid": "0x1", "name": "A.N. Author" } ] } 176 expected: | 177 { "getAuthor": { "name": "A.N. Author", "postsRequired": [ ] } } 178 179 - 180 name: "Missing nullable list becomes []" 181 gqlquery: | 182 query { 183 getAuthor(id: "0x1") { 184 name 185 postsNullable { 186 title 187 } 188 } 189 } 190 explanation: "When a field of any list type is missing in the result, 191 it should be added as an empty list [], not null" 192 response: | 193 { "getAuthor": [ { "uid": "0x1", "name": "A.N. Author" } ] } 194 expected: | 195 { "getAuthor": { "name": "A.N. Author", "postsNullable": [ ] } } 196 197 - 198 name: "Missing list becomes [] (aliased)" 199 gqlquery: | 200 query { 201 getAuthor(id: "0x1") { 202 name 203 posts : postsRequired { 204 title 205 } 206 } 207 } 208 explanation: "When a field of any list type is missing in the result, 209 it should be added as an empty list [], not null" 210 response: | 211 { "getAuthor": [ { "uid": "0x1", "name": "A.N. Author" } ] } 212 expected: | 213 { "getAuthor": { "name": "A.N. Author", "posts": [ ] } } 214 215 - 216 name: "Multiple missing lists become [] (with alias)" 217 gqlquery: | 218 query { 219 getAuthor(id: "0x1") { 220 name 221 posts : postsRequired { 222 title 223 } 224 postsNullable { 225 title 226 } 227 } 228 } 229 explanation: "When a field of any list type is missing in the result, 230 it should be added as an empty list [], not null" 231 response: | 232 { "getAuthor": [ { "uid": "0x1", "name": "A.N. Author" } ] } 233 expected: | 234 { "getAuthor": { "name": "A.N. Author", "posts": [ ], "postsNullable": [ ] } } 235 236 - 237 name: "Sensible error when expecting single but multiple items returned" 238 gqlquery: | 239 query { 240 getAuthor(id: "0x1") { 241 name 242 } 243 } 244 explanation: "When a query result is of a non-list type, we really should only 245 get one item in the Dgraph result." 246 response: | 247 { "getAuthor": [ 248 { "uid": "0x1", "name": "A.N. Author" }, 249 { "uid": "0x2", "name": "A.N. Other Author" } 250 ] } 251 expected: | 252 { "getAuthor": { "name": "A.N. Author" } } 253 errors: 254 [ { "message": "Dgraph returned a list, but getAuthor (type Author) was expecting just one 255 item. The first item in the list was used to produce the result. 256 Logged as a potential bug; see the API log for more details.", 257 "locations": [ { "column":3, "line":2 } ] } ] 258 259 - 260 name: "Sensible error when un-processable Dgraph result" 261 gqlquery: | 262 query { 263 getAuthor(id: "0x1") { 264 name 265 } 266 } 267 explanation: "Shouldn't happen" 268 response: | 269 { something is wrong } 270 expected: | 271 { "getAuthor": null } 272 errors: 273 [ { "message": "couldn't unmarshal Dgraph result 274 because invalid character 's' looking for beginning of object key string" , 275 "locations": [ { "column":3, "line":2 } ] } ] 276 277 - 278 name: "Error gets propagated to nullable parent if missing non-nullable field" 279 gqlquery: | 280 query { 281 getAuthor(id: "0x1") { 282 name 283 dob 284 } 285 } 286 explanation: "GraphQL error propagation causes an error on a non-nullable field 287 (like name: String!) to propagate to the parent object." 288 response: | 289 { "getAuthor": [ { "uid": "0x1", "dob": "2000-01-01" } ] } 290 expected: | 291 { "getAuthor": null } 292 errors: 293 [ { 294 "message": "Non-nullable field 'name' (type String!) was not present in 295 result from Dgraph. GraphQL error propagation triggered." , 296 "path": [ "getAuthor", "name" ], 297 "locations": [ { "line": 3, "column": 5 } ] } ] 298 299 - 300 name: "Error in [T!] list propagated as null list" 301 gqlquery: | 302 query { 303 getAuthor(id: "0x1") { 304 name 305 postsElmntRequired { 306 title 307 text 308 } 309 } 310 } 311 explanation: "If a list has non-nullable elements and an element becomes null, 312 here because title (String!) is missing, GraphQL error propagation 313 says the list becomes null." 314 response: | 315 { "getAuthor": [ 316 { "uid": "0x1", 317 "name": "A.N. Author", 318 "postsElmntRequired": [ 319 { "uid": "0x2", "title": "A Title", "text": "Some Text" }, 320 { "uid": "0x3", "text": "More Text" } 321 ] } 322 ] } 323 expected: | 324 { "getAuthor": { "name": "A.N. Author", "postsElmntRequired": null } } 325 errors: 326 [ { "message": "Non-nullable field 'title' (type String!) was not present 327 in result from Dgraph. GraphQL error propagation triggered.", 328 "path": [ "getAuthor", "postsElmntRequired", 1, "title" ], 329 "locations": [ { "line": 5, "column": 7 } ] } ] 330 331 - 332 name: "Only uid in [T!] list propagated as null list" 333 gqlquery: | 334 query { 335 getAuthor(id: "0x1") { 336 name 337 postsElmntRequired { 338 title 339 text 340 } 341 } 342 } 343 explanation: "If a list has non-nullable elements and an element becomes null, 344 here because title (String!) is missing, GraphQL error propagation 345 says the list becomes null." 346 response: | 347 { "getAuthor": [ 348 { "uid": "0x1", 349 "name": "A.N. Author", 350 "postsElmntRequired": [ 351 { "uid": "0x2", "title": "A Title", "text": "Some Text" }, 352 { "uid": "0x3" } 353 ] } 354 ] } 355 expected: | 356 { "getAuthor": { "name": "A.N. Author", "postsElmntRequired": null } } 357 errors: 358 [ { "message": "Non-nullable field 'title' (type String!) was not present 359 in result from Dgraph. GraphQL error propagation triggered.", 360 "path": [ "getAuthor", "postsElmntRequired", 1, "title" ], 361 "locations": [ { "line": 5, "column": 7 } ] } ] 362 363 - 364 name: "Error in [T] list propagated as null element in list" 365 gqlquery: | 366 query { 367 getAuthor(id: "0x1") { 368 name 369 postsNullable { 370 title 371 text 372 } 373 } 374 } 375 explanation: "The schema asserts a Post's title as non nullable (title: String!), 376 but allows nulls in an Author's postsNullable (postsNullable: [Post]). So a 377 post in the result list that's missing a title gets squashed to null" 378 response: | 379 { "getAuthor": [ 380 { "uid": "0x1", 381 "name": "A.N. Author", 382 "postsNullable": [ 383 { "uid": "0x2", "title": "A Title", "text": "Some Text" }, 384 { "uid": "0x3", "text": "More Text" } 385 ] } 386 ] } 387 expected: | 388 { "getAuthor": 389 { "name": "A.N. Author", 390 "postsNullable": [ 391 { "title": "A Title", "text": "Some Text" }, 392 null 393 ] } 394 } 395 errors: 396 [ { "message": "Non-nullable field 'title' (type String!) was not present 397 in result from Dgraph. GraphQL error propagation triggered.", 398 "path": [ "getAuthor", "postsNullable", 1, "title" ], 399 "locations": [ { "line": 5, "column": 7 } ] } ] 400 401 - 402 name: "Only uid in [T] list propagated as null element in list" 403 gqlquery: | 404 query { 405 getAuthor(id: "0x1") { 406 name 407 postsNullable { 408 title 409 } 410 } 411 } 412 explanation: "The schema asserts a Post's title as non nullable (title: String!), 413 but allows nulls in an Author's postsNullable (postsNullable: [Post]). So a 414 post in the result list that's missing a title gets squashed to null" 415 response: | 416 { "getAuthor": [ 417 { "uid": "0x1", 418 "name": "A.N. Author", 419 "postsNullable": [ 420 { "uid": "0x2" }, 421 { "uid": "0x3", "title": "A Title" } 422 ] } 423 ] } 424 expected: | 425 { "getAuthor": 426 { "name": "A.N. Author", 427 "postsNullable": [ 428 null, 429 { "title": "A Title" } 430 ] } 431 } 432 errors: 433 [ { "message": "Non-nullable field 'title' (type String!) was not present 434 in result from Dgraph. GraphQL error propagation triggered.", 435 "path": [ "getAuthor", "postsNullable", 0, "title" ], 436 "locations": [ { "line": 5, "column": 7 } ] } ] 437 438 - 439 name: "Many errors in [T] list propagated as null elements in list" 440 gqlquery: | 441 query { 442 getAuthor(id: "0x1") { 443 name 444 postsNullable { 445 text 446 title 447 } 448 } 449 } 450 explanation: "The schema asserts a Post's title as non nullable (title: String!), 451 but allows nulls in an Author's postsNullable (postsNullable: [Post]). So any 452 post in the result list that's missing a title gets squashed to null" 453 response: | 454 { "getAuthor": [ 455 { "uid": "0x1", 456 "name": "A.N. Author", 457 "postsNullable": [ 458 { "uid": "0x2", "text": "Some Text" }, 459 { "uid": "0x3", "title": "A Title", "text": "Some Text" }, 460 { "uid": "0x4" }, 461 { "uid": "0x5", "text": "Some Text" } 462 ] } 463 ] } 464 expected: | 465 { "getAuthor": 466 { "name": "A.N. Author", 467 "postsNullable": [ 468 null, 469 { "title": "A Title", "text": "Some Text" }, 470 null, 471 null 472 ] } 473 } 474 errors: 475 [ { "message": "Non-nullable field 'title' (type String!) was not present 476 in result from Dgraph. GraphQL error propagation triggered.", 477 "path": [ "getAuthor", "postsNullable", 0, "title" ], 478 "locations": [ { "line": 6, "column": 7 } ] }, 479 { "message": "Non-nullable field 'title' (type String!) was not present 480 in result from Dgraph. GraphQL error propagation triggered.", 481 "path": [ "getAuthor", "postsNullable", 2, "title" ], 482 "locations": [ { "line": 6, "column": 7 } ] }, 483 { "message": "Non-nullable field 'title' (type String!) was not present 484 in result from Dgraph. GraphQL error propagation triggered.", 485 "path": [ "getAuthor", "postsNullable", 3, "title" ], 486 "locations": [ { "line": 6, "column": 7 } ] } ] 487 488 - 489 name: "Only uid on nullable field list gets inserted correctly" 490 gqlquery: | 491 query { 492 getAuthor(id: "0x1") { 493 name 494 postsNullable { 495 text 496 } 497 } 498 } 499 explanation: "The schema asserts a Post's text as nullable (text: String), 500 so if a query finds posts without any text, nulls should be inserted" 501 response: | 502 { "getAuthor": [ 503 { "uid": "0x1", 504 "name": "A.N. Author", 505 "postsNullable": [ 506 { "uid": "0x2" }, 507 { "uid": "0x3", "text": "Some Text" }, 508 { "uid": "0x4" }, 509 { "uid": "0x5", "text": "Some Text" } 510 ] } 511 ] } 512 expected: | 513 { "getAuthor": 514 { "name": "A.N. Author", 515 "postsNullable": [ 516 { "text": null }, 517 { "text": "Some Text" }, 518 { "text": null }, 519 { "text": "Some Text" } 520 ] } 521 } 522 523 - 524 name: "Error in [T]! list propagated as null element in list" 525 gqlquery: | 526 query { 527 getAuthor(id: "0x1") { 528 name 529 postsNullableListRequired { 530 title 531 text 532 } 533 } 534 } 535 explanation: "The schema asserts a Post's title as non nullable (title: String!), 536 but allows nulls in an Author's postsNullable (postsNullable: [Post]). So a 537 post in the result list that's missing a title gets squashed to null" 538 response: | 539 { "getAuthor": [ 540 { "uid": "0x1", 541 "name": "A.N. Author", 542 "postsNullableListRequired": [ 543 { "uid": "0x3", "text": "More Text" }, 544 { "uid": "0x2", "title": "A Title", "text": "Some Text" } 545 ] } 546 ] } 547 expected: | 548 { "getAuthor": 549 { "name": "A.N. Author", 550 "postsNullableListRequired": [ 551 null, 552 { "title": "A Title", "text": "Some Text" } 553 ] } 554 } 555 errors: 556 [ { "message": "Non-nullable field 'title' (type String!) was not present 557 in result from Dgraph. GraphQL error propagation triggered.", 558 "path": [ "getAuthor", "postsNullableListRequired", 0, "title" ], 559 "locations": [ { "line": 5, "column": 7 } ] } ]