Skip to content

Commit 803626a

Browse files
committed
more
1 parent 98e0b56 commit 803626a

File tree

7 files changed

+205
-52
lines changed

7 files changed

+205
-52
lines changed

packages/plugin/src/rules/naming-convention/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ const schema = {
118118
kind,
119119
{
120120
...schemaOption,
121-
description: `Read more about this kind on [spec.graphql.org](https://spec.graphql.org/October2021/#${kind}).`,
121+
description: `> [!NOTE]
122+
>
123+
> Read more about this kind on [spec.graphql.org](https://spec.graphql.org/October2021/#${kind}).`,
122124
},
123125
]),
124126
),

packages/plugin/src/rules/no-unused-fields/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { FromSchema } from 'json-schema-to-ts';
44
import { ModuleCache } from '../../cache.js';
55
import { SiblingOperations } from '../../siblings.js';
66
import { GraphQLESLintRule, GraphQLESTreeNode } from '../../types.js';
7-
import { requireGraphQLOperations, requireGraphQLSchema } from '../../utils.js';
7+
import { eslintSelectorsTip, requireGraphQLOperations, requireGraphQLSchema } from "../../utils.js";
88

99
const RULE_ID = 'no-unused-fields';
1010

@@ -89,9 +89,7 @@ const schema = {
8989
'```json',
9090
JSON.stringify(RELAY_DEFAULT_IGNORED_FIELD_SELECTORS, null, 2),
9191
'```',
92-
'',
93-
'> These fields are defined by ESLint [`selectors`](https://eslint.org/docs/developer-guide/selectors).',
94-
'> Paste or drop code into the editor in [ASTExplorer](https://astexplorer.net) and inspect the generated AST to compose your selector.',
92+
eslintSelectorsTip
9593
].join('\n'),
9694
items: {
9795
type: 'string',

packages/plugin/src/rules/require-description/index.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,45 @@ ruleTester.run<RuleOptions>('require-description', rule, {
228228
options: [{ rootField: true }],
229229
errors: [{ messageId: RULE_ID }],
230230
},
231+
{
232+
only: true,
233+
name: 'ignoredSelectors',
234+
options: [{ types: true,
235+
ignoredSelectors: [
236+
'[type=ObjectTypeDefinition][name.value=PageInfo]',
237+
'[type=ObjectTypeDefinition][name.value=/(Connection|Edge)$/]',
238+
]
239+
}],
240+
code: /* GraphQL */ `
241+
type Query {
242+
user: User
243+
}
244+
type User {
245+
id: ID!
246+
name: String!
247+
friends(first: Int, after: String): FriendConnection!
248+
}
249+
type FriendConnection {
250+
edges: [FriendEdge]
251+
pageInfo: PageInfo!
252+
}
253+
type FriendEdge {
254+
cursor: String!
255+
node: Friend!
256+
}
257+
type Friend {
258+
id: ID!
259+
name: String!
260+
}
261+
type PageInfo {
262+
hasPreviousPage: Boolean!
263+
hasNextPage: Boolean!
264+
startCursor: String
265+
endCursor: String
266+
}
267+
`,
268+
errors: 3,
269+
}
231270
],
232271
});
233272

packages/plugin/src/rules/require-description/snapshot.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,67 @@ exports[`require-description > invalid > Invalid #19 1`] = `
228228
3 | }
229229
`;
230230

231+
exports[`require-description > invalid > ignoredSelectors 1`] = `
232+
#### ⌨️ Code
233+
234+
1 | type Query {
235+
2 | user: User
236+
3 | }
237+
4 | type User {
238+
5 | id: ID!
239+
6 | name: String!
240+
7 | friends(first: Int, after: String): FriendConnection!
241+
8 | }
242+
9 | type FriendConnection {
243+
10 | edges: [FriendEdge]
244+
11 | pageInfo: PageInfo!
245+
12 | }
246+
13 | type FriendEdge {
247+
14 | cursor: String!
248+
15 | node: Friend!
249+
16 | }
250+
17 | type Friend {
251+
18 | id: ID!
252+
19 | name: String!
253+
20 | }
254+
21 | type PageInfo {
255+
22 | hasPreviousPage: Boolean!
256+
23 | hasNextPage: Boolean!
257+
24 | startCursor: String
258+
25 | endCursor: String
259+
26 | }
260+
261+
#### ⚙️ Options
262+
263+
{
264+
"types": true,
265+
"ignoredSelectors": [
266+
"[type=ObjectTypeDefinition][name.value=PageInfo]",
267+
"[type=ObjectTypeDefinition][name.value=/(Connection|Edge)$/]"
268+
]
269+
}
270+
271+
#### ❌ Error 1/3
272+
273+
> 1 | type Query {
274+
| ^^^^^ Description is required for type "Query"
275+
2 | user: User
276+
277+
#### ❌ Error 2/3
278+
279+
3 | }
280+
> 4 | type User {
281+
| ^^^^ Description is required for type "User"
282+
5 | id: ID!
283+
284+
#### ❌ Error 3/3
285+
286+
16 | }
287+
> 17 | type Friend {
288+
| ^^^^^^ Description is required for type "Friend"
289+
18 | id: ID!
290+
`;
291+
231292
exports[`require-description > invalid > should disable description for ObjectTypeDefinition 1`] = `
232293
#### ⌨️ Code
233294

packages/plugin/src/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,3 +200,8 @@ export function getNodeName(node: GraphQLESTreeNode<ASTNode>): string {
200200
}
201201
return '';
202202
}
203+
204+
export const eslintSelectorsTip = `> [!TIP]
205+
>
206+
> These fields are defined by ESLint [\`selectors\`](https://eslint.org/docs/developer-guide/selectors).
207+
> Paste or drop code into the editor in [ASTExplorer](https://astexplorer.net) and inspect the generated AST to compose your selector.`

website/content/rules/naming-convention.mdx

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ The object must be one of the following types:
149149

150150
### `Argument`
151151

152-
Read more about this kind on [spec.graphql.org](https://spec.graphql.org/October2021/#Argument).
152+
> [!NOTE]
153+
>
154+
> Read more about this kind on [spec.graphql.org](https://spec.graphql.org/October2021/#Argument).
153155

154156
The object must be one of the following types:
155157

@@ -158,8 +160,10 @@ The object must be one of the following types:
158160

159161
### `DirectiveDefinition`
160162

161-
Read more about this kind on
162-
[spec.graphql.org](https://spec.graphql.org/October2021/#DirectiveDefinition).
163+
> [!NOTE]
164+
>
165+
> Read more about this kind on
166+
> [spec.graphql.org](https://spec.graphql.org/October2021/#DirectiveDefinition).
163167

164168
The object must be one of the following types:
165169

@@ -168,8 +172,10 @@ The object must be one of the following types:
168172

169173
### `EnumTypeDefinition`
170174

171-
Read more about this kind on
172-
[spec.graphql.org](https://spec.graphql.org/October2021/#EnumTypeDefinition).
175+
> [!NOTE]
176+
>
177+
> Read more about this kind on
178+
> [spec.graphql.org](https://spec.graphql.org/October2021/#EnumTypeDefinition).
173179

174180
The object must be one of the following types:
175181

@@ -178,8 +184,10 @@ The object must be one of the following types:
178184

179185
### `EnumValueDefinition`
180186

181-
Read more about this kind on
182-
[spec.graphql.org](https://spec.graphql.org/October2021/#EnumValueDefinition).
187+
> [!NOTE]
188+
>
189+
> Read more about this kind on
190+
> [spec.graphql.org](https://spec.graphql.org/October2021/#EnumValueDefinition).
183191

184192
The object must be one of the following types:
185193

@@ -188,8 +196,10 @@ The object must be one of the following types:
188196

189197
### `FieldDefinition`
190198

191-
Read more about this kind on
192-
[spec.graphql.org](https://spec.graphql.org/October2021/#FieldDefinition).
199+
> [!NOTE]
200+
>
201+
> Read more about this kind on
202+
> [spec.graphql.org](https://spec.graphql.org/October2021/#FieldDefinition).
193203

194204
The object must be one of the following types:
195205

@@ -198,8 +208,10 @@ The object must be one of the following types:
198208

199209
### `FragmentDefinition`
200210

201-
Read more about this kind on
202-
[spec.graphql.org](https://spec.graphql.org/October2021/#FragmentDefinition).
211+
> [!NOTE]
212+
>
213+
> Read more about this kind on
214+
> [spec.graphql.org](https://spec.graphql.org/October2021/#FragmentDefinition).
203215

204216
The object must be one of the following types:
205217

@@ -208,8 +220,10 @@ The object must be one of the following types:
208220

209221
### `InputObjectTypeDefinition`
210222

211-
Read more about this kind on
212-
[spec.graphql.org](https://spec.graphql.org/October2021/#InputObjectTypeDefinition).
223+
> [!NOTE]
224+
>
225+
> Read more about this kind on
226+
> [spec.graphql.org](https://spec.graphql.org/October2021/#InputObjectTypeDefinition).
213227

214228
The object must be one of the following types:
215229

@@ -218,8 +232,10 @@ The object must be one of the following types:
218232

219233
### `InputValueDefinition`
220234

221-
Read more about this kind on
222-
[spec.graphql.org](https://spec.graphql.org/October2021/#InputValueDefinition).
235+
> [!NOTE]
236+
>
237+
> Read more about this kind on
238+
> [spec.graphql.org](https://spec.graphql.org/October2021/#InputValueDefinition).
223239

224240
The object must be one of the following types:
225241

@@ -228,8 +244,10 @@ The object must be one of the following types:
228244

229245
### `InterfaceTypeDefinition`
230246

231-
Read more about this kind on
232-
[spec.graphql.org](https://spec.graphql.org/October2021/#InterfaceTypeDefinition).
247+
> [!NOTE]
248+
>
249+
> Read more about this kind on
250+
> [spec.graphql.org](https://spec.graphql.org/October2021/#InterfaceTypeDefinition).
233251

234252
The object must be one of the following types:
235253

@@ -238,8 +256,10 @@ The object must be one of the following types:
238256

239257
### `ObjectTypeDefinition`
240258

241-
Read more about this kind on
242-
[spec.graphql.org](https://spec.graphql.org/October2021/#ObjectTypeDefinition).
259+
> [!NOTE]
260+
>
261+
> Read more about this kind on
262+
> [spec.graphql.org](https://spec.graphql.org/October2021/#ObjectTypeDefinition).
243263

244264
The object must be one of the following types:
245265

@@ -248,8 +268,10 @@ The object must be one of the following types:
248268

249269
### `OperationDefinition`
250270

251-
Read more about this kind on
252-
[spec.graphql.org](https://spec.graphql.org/October2021/#OperationDefinition).
271+
> [!NOTE]
272+
>
273+
> Read more about this kind on
274+
> [spec.graphql.org](https://spec.graphql.org/October2021/#OperationDefinition).
253275

254276
The object must be one of the following types:
255277

@@ -258,8 +280,10 @@ The object must be one of the following types:
258280

259281
### `ScalarTypeDefinition`
260282

261-
Read more about this kind on
262-
[spec.graphql.org](https://spec.graphql.org/October2021/#ScalarTypeDefinition).
283+
> [!NOTE]
284+
>
285+
> Read more about this kind on
286+
> [spec.graphql.org](https://spec.graphql.org/October2021/#ScalarTypeDefinition).
263287

264288
The object must be one of the following types:
265289

@@ -268,8 +292,10 @@ The object must be one of the following types:
268292

269293
### `UnionTypeDefinition`
270294

271-
Read more about this kind on
272-
[spec.graphql.org](https://spec.graphql.org/October2021/#UnionTypeDefinition).
295+
> [!NOTE]
296+
>
297+
> Read more about this kind on
298+
> [spec.graphql.org](https://spec.graphql.org/October2021/#UnionTypeDefinition).
273299

274300
The object must be one of the following types:
275301

@@ -278,8 +304,10 @@ The object must be one of the following types:
278304

279305
### `VariableDefinition`
280306

281-
Read more about this kind on
282-
[spec.graphql.org](https://spec.graphql.org/October2021/#VariableDefinition).
307+
> [!NOTE]
308+
>
309+
> Read more about this kind on
310+
> [spec.graphql.org](https://spec.graphql.org/October2021/#VariableDefinition).
283311

284312
The object must be one of the following types:
285313

0 commit comments

Comments
 (0)