-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes for rawNode and validation rule (#67)
- Loading branch information
1 parent
6d1cfe9
commit 80e922c
Showing
6 changed files
with
212 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@graphql-eslint/eslint-plugin': minor | ||
--- | ||
|
||
Improved `validate-against-schema` rule configuration (allow to customize rules) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@graphql-eslint/eslint-plugin': patch | ||
--- | ||
|
||
Fix issues with `.rawNode()` values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { GraphQLRuleTester } from '../src/testkit'; | ||
import rule from '../src/rules/validate-against-schema'; | ||
|
||
const TEST_SCHEMA = /* GraphQL */ ` | ||
type Query { | ||
user(id: ID!): User! | ||
} | ||
type User { | ||
id: ID! | ||
name: String! | ||
} | ||
`; | ||
|
||
const WITH_SCHEMA = { parserOptions: { schema: TEST_SCHEMA } }; | ||
const ruleTester = new GraphQLRuleTester(); | ||
|
||
ruleTester.runGraphQLTests('validate-against-schema', rule, { | ||
valid: [ | ||
{ ...WITH_SCHEMA, code: `query { user(id: 1) { id } }` }, | ||
{ ...WITH_SCHEMA, code: `query test($id: ID!) { user(id: $id) { id } }` }, | ||
{ ...WITH_SCHEMA, code: `query named ($id: ID!) { user(id: $id) { id } }` }, | ||
{ | ||
...WITH_SCHEMA, | ||
options: [{ disableRules: ['KnownDirectivesRule'] }], | ||
code: `query named ($id: ID!) { user(id: $id) { id @client } }`, | ||
}, | ||
{ | ||
...WITH_SCHEMA, | ||
options: [{ overrideRules: ['NoUnusedVariablesRule'] }], | ||
code: `query named ($id: ID!) { user(id: $id) { id @client } }`, | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
...WITH_SCHEMA, | ||
code: `query { user(id: 1) { notExists } }`, | ||
errors: ['Cannot query field "notExists" on type "User".'], | ||
}, | ||
{ | ||
...WITH_SCHEMA, | ||
options: [{ overrideRules: ['NoUnusedVariablesRule'] }], | ||
code: `query named ($id: ID!) { user(id: 2) { id @client } }`, | ||
errors: ['Variable "$id" is never used in operation "named".'], | ||
}, | ||
{ | ||
...WITH_SCHEMA, | ||
errors: ['Unknown directive "@client".'], | ||
code: `query named ($id: ID!) { user(id: $id) { id @client } }`, | ||
}, | ||
{ | ||
...WITH_SCHEMA, | ||
errors: ['Unknown directive "@client".'], | ||
options: [{ overrideRules: ['KnownDirectivesRule'] }], | ||
code: `query named ($id: ID!) { user(id: $id) { id @client } }`, | ||
}, | ||
{ | ||
...WITH_SCHEMA, | ||
code: `query test($id: ID!) { user(invalid: $id) { test } }`, | ||
errors: [ | ||
'Unknown argument "invalid" on field "Query.user".', | ||
'Cannot query field "test" on type "User".', | ||
'Field "user" argument "id" of type "ID!" is required, but it was not provided.', | ||
], | ||
}, | ||
], | ||
}); |