Skip to content

Commit 1103892

Browse files
authored
WIP - Use GraphQL methods (#83)
* Add GraphQL validations * Add GraphQL validations * Remove query parser * Refactor fixture * Rename mock method * Ignore KnownDirectivesRule * Update readme
1 parent 106cb7c commit 1103892

23 files changed

+2047
-1915
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
Select a easygraphql-tester version below to view the changelog history:
44

5-
* [easygraphql-tester v4](doc/changelogs/CHANGELOG_V4.md) - **Current**
5+
* [easygraphql-tester v5](doc/changelogs/CHANGELOG_V5.md) - **Current**
6+
* [easygraphql-tester v4](doc/changelogs/CHANGELOG_V4.md)
67
* [easygraphql-tester v3](doc/changelogs/CHANGELOG_V3.md)

README.MD

Lines changed: 2 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ Call the method `.mock()` and pass an object with this options:
241241
it will return the fixture value.
242242
+ validateDeprecated: If you want to validate if the query is requesting a deprecated field, set this option to `true`
243243
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: [...] }`
244246

245247
The result will have top level fields, it means that the result will be an object
246248
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
426428
}
427429
```
428430

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-
538431
## Demo
539432
Here is a [Demo](https://codesandbox.io/embed/42m2rx71j4?previewwindow=tests&view=preview) that can be useful!
540433

doc/changelogs/CHANGELOG_V5.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# easygraphql-tester V5 ChangeLog
2+
3+
<table>
4+
<tr>
5+
<th>Current</th>
6+
</tr>
7+
<tr>
8+
<td>
9+
<a href="#5.0.0">5.0.0</a><br/>
10+
</td>
11+
</tr>
12+
</table>
13+
14+
<a id="5.0.0"></a>
15+
## Version 5.0.0
16+
17+
### Notable Changes
18+
19+
* **Execute with GraphQL**: Execute the operation with GraphQL internal method.
20+
* **Validate with GraphQL**: Validate the operation with GraphQL internal method, ignore KnownDirectivesRule.
21+
* **Parse the operation with GraphQL**: Parse the document with GraphQL internal method, and remove query-parser.
22+
23+
### Commits

lib/queryParser.js

Lines changed: 0 additions & 237 deletions
This file was deleted.

0 commit comments

Comments
 (0)