Skip to content

Commit a92267b

Browse files
authored
fixes for graphql-js rules issues (#433)
1 parent 8e1a0e6 commit a92267b

File tree

3 files changed

+94
-24
lines changed

3 files changed

+94
-24
lines changed

.changeset/long-apricots-taste.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': patch
3+
---
4+
5+
fixes for graphql-js rules issues

packages/plugin/src/rules/graphql-js-validation.ts

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,16 @@ export const GRAPHQL_JS_VALIDATIONS = Object.assign(
180180
description: `A fragment spread is only valid if the type condition could ever possibly be true: if there is a non-empty intersection of the possible parent types, and possible types which pass the type condition.`,
181181
},
182182
}),
183-
validationToRule('possible-type-extension', 'PossibleTypeExtensions', {
184-
docs: {
185-
description: `A type extension is only valid if the type is defined and has the same kind.`,
183+
validationToRule(
184+
'possible-type-extension',
185+
'PossibleTypeExtensions',
186+
{
187+
docs: {
188+
description: `A type extension is only valid if the type is defined and has the same kind.`,
189+
},
186190
},
187-
}),
191+
true
192+
),
188193
validationToRule('provided-required-arguments', 'ProvidedRequiredArguments', {
189194
docs: {
190195
description: `A field or directive is only valid if all required (non-null without a default value) field arguments have been provided.`,
@@ -205,36 +210,61 @@ export const GRAPHQL_JS_VALIDATIONS = Object.assign(
205210
description: `A GraphQL field or directive is only valid if all supplied arguments are uniquely named.`,
206211
},
207212
}),
208-
validationToRule('unique-directive-names', 'UniqueDirectiveNames', {
209-
docs: {
210-
description: `A GraphQL document is only valid if all defined directives have unique names.`,
213+
validationToRule(
214+
'unique-directive-names',
215+
'UniqueDirectiveNames',
216+
{
217+
docs: {
218+
description: `A GraphQL document is only valid if all defined directives have unique names.`,
219+
},
211220
},
212-
}),
221+
true
222+
),
213223
validationToRule('unique-directive-names-per-location', 'UniqueDirectivesPerLocation', {
214224
docs: {
215225
description: `A GraphQL document is only valid if all non-repeatable directives at a given location are uniquely named.`,
216226
},
217227
}),
218-
validationToRule('unique-enum-value-names', 'UniqueEnumValueNames', {
219-
docs: {
220-
description: `A GraphQL enum type is only valid if all its values are uniquely named.`,
228+
validationToRule(
229+
'unique-enum-value-names',
230+
'UniqueEnumValueNames',
231+
{
232+
docs: {
233+
description: `A GraphQL enum type is only valid if all its values are uniquely named.`,
234+
},
221235
},
222-
}),
223-
validationToRule('unique-field-definition-names', 'UniqueFieldDefinitionNames', {
224-
docs: {
225-
description: `A GraphQL complex type is only valid if all its fields are uniquely named.`,
236+
true
237+
),
238+
validationToRule(
239+
'unique-field-definition-names',
240+
'UniqueFieldDefinitionNames',
241+
{
242+
docs: {
243+
description: `A GraphQL complex type is only valid if all its fields are uniquely named.`,
244+
},
226245
},
227-
}),
228-
validationToRule('unique-input-field-names', 'UniqueInputFieldNames', {
229-
docs: {
230-
description: `A GraphQL input object value is only valid if all supplied fields are uniquely named.`,
246+
true
247+
),
248+
validationToRule(
249+
'unique-input-field-names',
250+
'UniqueInputFieldNames',
251+
{
252+
docs: {
253+
description: `A GraphQL input object value is only valid if all supplied fields are uniquely named.`,
254+
},
231255
},
232-
}),
233-
validationToRule('unique-operation-types', 'UniqueOperationTypes', {
234-
docs: {
235-
description: `A GraphQL document is only valid if it has only one type per operation.`,
256+
true
257+
),
258+
validationToRule(
259+
'unique-operation-types',
260+
'UniqueOperationTypes',
261+
{
262+
docs: {
263+
description: `A GraphQL document is only valid if it has only one type per operation.`,
264+
},
236265
},
237-
}),
266+
true
267+
),
238268
validationToRule(
239269
'unique-type-names',
240270
'UniqueTypeNames',
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { GraphQLRuleTester } from '../src/testkit';
2+
import { GRAPHQL_JS_VALIDATIONS } from '../src/rules/graphql-js-validation';
3+
import { ParserOptions } from '../src/types';
4+
5+
const ruleTester = new GraphQLRuleTester();
6+
7+
ruleTester.runGraphQLTests('possible-type-extension', GRAPHQL_JS_VALIDATIONS['possible-type-extension'], {
8+
valid: [
9+
{
10+
code: /* GraphQL */ `
11+
type User {
12+
id: ID!
13+
}
14+
15+
extend type User {
16+
name: String!
17+
}
18+
`,
19+
},
20+
],
21+
invalid: [
22+
{
23+
code: /* GraphQL */ `
24+
type User {
25+
id: ID!
26+
}
27+
28+
extend type OtherUser {
29+
name: String!
30+
}
31+
`,
32+
errors: [{ message: 'Cannot extend type "OtherUser" because it is not defined.' }],
33+
},
34+
],
35+
});

0 commit comments

Comments
 (0)