@@ -241,6 +241,8 @@ Call the method `.mock()` and pass an object with this options:
241
241
it will return the fixture value.
242
242
+ validateDeprecated: If you want to validate if the query is requesting a deprecated field, set this option to ` true `
243
243
and it'll return an error if a field is deprecated.
244
+ + mockErrors: If you want to mock the errors instead of throwing it, set this option to ` true ` and now, the responsw will have
245
+ ` { data: ..., errors: [...] } `
244
246
245
247
The result will have top level fields, it means that the result will be an object
246
248
with a property that is going to be ` data ` and inside it the name (top level field)
@@ -426,115 +428,6 @@ const { data: { createUser } } = tester.mock({ query: mutation, variables: input
426
428
}
427
429
```
428
430
429
- ## Errors
430
-
431
- If there is an error on the query or mutation [ ` easygraphql-tester ` ] ( https://github.com/EasyGraphQL/easygraphql-tester ) will let you know what
432
- is happening.
433
-
434
- ### Invalid field on query
435
- ``` js
436
- ' use strict'
437
-
438
- const EasyGraphQLTester = require (' easygraphql-tester' )
439
- const fs = require (' fs' )
440
- const path = require (' path' )
441
-
442
- const userSchema = fs .readFileSync (path .join (__dirname , ' schema' , ' user.gql' ), ' utf8' )
443
- const familySchema = fs .readFileSync (path .join (__dirname , ' schema' , ' family.gql' ), ' utf8' )
444
-
445
- const tester = new EasyGraphQLTester ([userSchema, familySchema])
446
-
447
- const query = `
448
- {
449
- getUsers {
450
- email
451
- username
452
- invalidName
453
- }
454
- }
455
- `
456
-
457
- tester .mock (query) // Error: Query getUsers: The selected field invalidName doesn't exists
458
- ```
459
-
460
- ### Invalid arguments on query
461
- ``` js
462
- ' use strict'
463
-
464
- const EasyGraphQLTester = require (' easygraphql-tester' )
465
- const fs = require (' fs' )
466
- const path = require (' path' )
467
-
468
- const userSchema = fs .readFileSync (path .join (__dirname , ' schema' , ' user.gql' ), ' utf8' )
469
- const familySchema = fs .readFileSync (path .join (__dirname , ' schema' , ' family.gql' ), ' utf8' )
470
-
471
- const tester = new EasyGraphQLTester ([userSchema, familySchema])
472
-
473
- const getUserByUsername = `
474
- {
475
- getUserByUsername(invalidArg: test) {
476
- email
477
- }
478
- }
479
- `
480
-
481
- tester .mock (getUserByUsername) // Error: invalidArg argument is not defined on getUserByUsername arguments
482
- ```
483
-
484
- ### Not defined argument on query
485
- ``` js
486
- ' use strict'
487
-
488
- const EasyGraphQLTester = require (' easygraphql-tester' )
489
- const fs = require (' fs' )
490
- const path = require (' path' )
491
-
492
- const userSchema = fs .readFileSync (path .join (__dirname , ' schema' , ' user.gql' ), ' utf8' )
493
- const familySchema = fs .readFileSync (path .join (__dirname , ' schema' , ' family.gql' ), ' utf8' )
494
-
495
- const tester = new EasyGraphQLTester ([userSchema, familySchema])
496
-
497
- const getUserByUsername = `
498
- {
499
- getUserByUsername(username: test, name: "name test") {
500
- email
501
- }
502
- }
503
- `
504
-
505
- tester .mock (getUserByUsername) // Error: name argument is not defined on getUserByUsername arguments
506
- ```
507
-
508
- ### Missing field on input
509
- ``` js
510
- ' use strict'
511
-
512
- const EasyGraphQLTester = require (' easygraphql-tester' )
513
- const fs = require (' fs' )
514
- const path = require (' path' )
515
-
516
- const userSchema = fs .readFileSync (path .join (__dirname , ' schema' , ' user.gql' ), ' utf8' )
517
- const familySchema = fs .readFileSync (path .join (__dirname , ' schema' , ' family.gql' ), ' utf8' )
518
-
519
- const tester = new EasyGraphQLTester ([userSchema, familySchema])
520
-
521
- const mutation = `
522
- mutation CreateFamily($input: CreateFamilyInput!) {
523
- createFamily(input: $input) {
524
- lastName
525
- }
526
- }
527
- `
528
- const test = tester .mock (mutation, {
529
- input: {
530
- lastName: ' test'
531
- }
532
- })
533
- // Error: email argument is missing on createFamily
534
- ```
535
-
536
- There are more errors, these ones are just some of the validations that are made.
537
-
538
431
## Demo
539
432
Here is a [ Demo] ( https://codesandbox.io/embed/42m2rx71j4?previewwindow=tests&view=preview ) that can be useful!
540
433
0 commit comments