Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`known-directives > invalid > should work only with Kind.FIELD 1`] = `
exports[`known-directives > invalid > should not ignore directives on schema definitions 1`] = `
#### ⌨️ Code

1 | scalar Foo @bad
Expand Down
42 changes: 40 additions & 2 deletions packages/plugin/__tests__/known-directives.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { RuleTester } from '@theguild/eslint-rule-tester';
import { GRAPHQL_JS_VALIDATIONS } from '../src/rules/graphql-js-validation.js';
import { DEFAULT_CONFIG, ParserOptionsForTests } from './test-utils.js';
import type { ParserOptionsForTests } from './test-utils.js';
import { DEFAULT_CONFIG } from './test-utils.js';

const ruleTester = new RuleTester<ParserOptionsForTests>({
languageOptions: {
Expand Down Expand Up @@ -55,10 +56,47 @@ ruleTester.run<[{ ignoreClientDirectives: string[] }]>(
`,
options: [{ ignoreClientDirectives: ['api'] }],
},
{
name: 'should ignore client directives on FragmentDefinition',
code: /* GraphQL */ `
fragment UserFields on User @client {
id
}
`,
options: [{ ignoreClientDirectives: ['client'] }],
},
{
name: 'should ignore client directives on InlineFragment',
code: /* GraphQL */ `
{
user {
... on User @client {
id
}
}
}
`,
options: [{ ignoreClientDirectives: ['client'] }],
},
{
name: 'should ignore client directives on FragmentSpread',
code: /* GraphQL */ `
fragment UserFields on User {
id
}

{
user {
...UserFields @client
}
}
`,
options: [{ ignoreClientDirectives: ['client'] }],
},
],
invalid: [
{
name: 'should work only with Kind.FIELD',
name: 'should not ignore directives on schema definitions',
code: 'scalar Foo @bad',
options: [{ ignoreClientDirectives: ['bad'] }],
errors: [{ message: 'Unknown directive "@bad".' }],
Expand Down
3 changes: 3 additions & 0 deletions packages/plugin/src/rules/graphql-js-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ export const GRAPHQL_JS_VALIDATIONS: Record<string, GraphQLESLintRule> = Object.

return visit(documentNode, {
Field: filterDirectives,
FragmentDefinition: filterDirectives,
FragmentSpread: filterDirectives,
InlineFragment: filterDirectives,
OperationDefinition: filterDirectives,
});
},
Expand Down