Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GraphQL methods #83

Merged
merged 7 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

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

* [easygraphql-tester v4](doc/changelogs/CHANGELOG_V4.md) - **Current**
* [easygraphql-tester v5](doc/changelogs/CHANGELOG_V5.md) - **Current**
* [easygraphql-tester v4](doc/changelogs/CHANGELOG_V4.md)
* [easygraphql-tester v3](doc/changelogs/CHANGELOG_V3.md)
111 changes: 2 additions & 109 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ Call the method `.mock()` and pass an object with this options:
it will return the fixture value.
+ validateDeprecated: If you want to validate if the query is requesting a deprecated field, set this option to `true`
and it'll return an error if a field is deprecated.
+ mockErrors: If you want to mock the errors instead of throwing it, set this option to `true` and now, the responsw will have
`{ data: ..., errors: [...] }`

The result will have top level fields, it means that the result will be an object
with a property that is going to be `data` and inside it the name (top level field)
Expand Down Expand Up @@ -426,115 +428,6 @@ const { data: { createUser } } = tester.mock({ query: mutation, variables: input
}
```

## Errors

If there is an error on the query or mutation [`easygraphql-tester`](https://github.com/EasyGraphQL/easygraphql-tester) will let you know what
is happening.

### Invalid field on query
```js
'use strict'

const EasyGraphQLTester = require('easygraphql-tester')
const fs = require('fs')
const path = require('path')

const userSchema = fs.readFileSync(path.join(__dirname, 'schema', 'user.gql'), 'utf8')
const familySchema = fs.readFileSync(path.join(__dirname, 'schema', 'family.gql'), 'utf8')

const tester = new EasyGraphQLTester([userSchema, familySchema])

const query = `
{
getUsers {
email
username
invalidName
}
}
`

tester.mock(query) // Error: Query getUsers: The selected field invalidName doesn't exists
```

### Invalid arguments on query
```js
'use strict'

const EasyGraphQLTester = require('easygraphql-tester')
const fs = require('fs')
const path = require('path')

const userSchema = fs.readFileSync(path.join(__dirname, 'schema', 'user.gql'), 'utf8')
const familySchema = fs.readFileSync(path.join(__dirname, 'schema', 'family.gql'), 'utf8')

const tester = new EasyGraphQLTester([userSchema, familySchema])

const getUserByUsername = `
{
getUserByUsername(invalidArg: test) {
email
}
}
`

tester.mock(getUserByUsername) // Error: invalidArg argument is not defined on getUserByUsername arguments
```

### Not defined argument on query
```js
'use strict'

const EasyGraphQLTester = require('easygraphql-tester')
const fs = require('fs')
const path = require('path')

const userSchema = fs.readFileSync(path.join(__dirname, 'schema', 'user.gql'), 'utf8')
const familySchema = fs.readFileSync(path.join(__dirname, 'schema', 'family.gql'), 'utf8')

const tester = new EasyGraphQLTester([userSchema, familySchema])

const getUserByUsername = `
{
getUserByUsername(username: test, name: "name test") {
email
}
}
`

tester.mock(getUserByUsername) // Error: name argument is not defined on getUserByUsername arguments
```

### Missing field on input
```js
'use strict'

const EasyGraphQLTester = require('easygraphql-tester')
const fs = require('fs')
const path = require('path')

const userSchema = fs.readFileSync(path.join(__dirname, 'schema', 'user.gql'), 'utf8')
const familySchema = fs.readFileSync(path.join(__dirname, 'schema', 'family.gql'), 'utf8')

const tester = new EasyGraphQLTester([userSchema, familySchema])

const mutation = `
mutation CreateFamily($input: CreateFamilyInput!) {
createFamily(input: $input) {
lastName
}
}
`
const test = tester.mock(mutation, {
input: {
lastName: 'test'
}
})
// Error: email argument is missing on createFamily
```

There are more errors, these ones are just some of the validations that are made.

## Demo
Here is a [Demo](https://codesandbox.io/embed/42m2rx71j4?previewwindow=tests&view=preview) that can be useful!

Expand Down
23 changes: 23 additions & 0 deletions doc/changelogs/CHANGELOG_V5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# easygraphql-tester V5 ChangeLog

<table>
<tr>
<th>Current</th>
</tr>
<tr>
<td>
<a href="#5.0.0">5.0.0</a><br/>
</td>
</tr>
</table>

<a id="5.0.0"></a>
## Version 5.0.0

### Notable Changes

* **Execute with GraphQL**: Execute the operation with GraphQL internal method.
* **Validate with GraphQL**: Validate the operation with GraphQL internal method, ignore KnownDirectivesRule.
* **Parse the operation with GraphQL**: Parse the document with GraphQL internal method, and remove query-parser.

### Commits
237 changes: 0 additions & 237 deletions lib/queryParser.js

This file was deleted.

Loading