Skip to content

Commit 241936a

Browse files
authored
update docs before stable release and rename requireSiblingsOperations to requireGraphQLOperations, rename requireGraphQLSchemaFromContext to requireGraphQLSchema (#2768)
* more * more * more * more * more * more * more * more * more * more * more * prettier * fix lint * rm * rmm * more * more
1 parent 88a6391 commit 241936a

File tree

28 files changed

+152
-163
lines changed

28 files changed

+152
-163
lines changed

.changeset/sour-peaches-prove.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': major
3+
---
4+
5+
- rename `requireSiblingsOperations` to `requireGraphQLOperations`
6+
- rename `requireGraphQLSchemaFromContext` to `requireGraphQLSchema`

.eslintrc.cjs

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ module.exports = {
123123
files: ['website/**/*.mdx/**'],
124124
rules: {
125125
'import/no-default-export': 'off',
126+
'no-dupe-keys': 'off', // Usage examples contains duplicate keys
126127
},
127128
},
128129
],

packages/plugin/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export * from './types.js';
77
export type { IGraphQLConfig } from 'graphql-config';
88
export type { GraphQLTagPluckOptions } from '@graphql-tools/graphql-tag-pluck';
99

10-
export { requireGraphQLSchemaFromContext, requireSiblingsOperations } from './utils.js';
10+
export { requireGraphQLSchema, requireGraphQLOperations } from './utils.js';
1111

1212
export const processors = { graphql: processor };
1313

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

+5-7
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ import { GraphQLESLintRule, GraphQLESLintRuleContext, RuleDocsInfo } from '../ty
5151
import {
5252
ARRAY_DEFAULT_OPTIONS,
5353
REPORT_ON_FIRST_CHARACTER,
54-
requireGraphQLSchemaFromContext,
55-
requireSiblingsOperations,
54+
requireGraphQLOperations,
55+
requireGraphQLSchema,
5656
} from '../utils.js';
5757

5858
type GraphQLJSRule = ValidationRule | SDLValidationRule;
@@ -161,7 +161,7 @@ type GetDocumentNode = (props: {
161161
const handleMissingFragments: GetDocumentNode = ({ ruleId, context, node }) => {
162162
const missingFragments = getMissingFragments(node);
163163
if (missingFragments.length > 0) {
164-
const siblings = requireSiblingsOperations(ruleId, context);
164+
const siblings = requireGraphQLOperations(ruleId, context);
165165
const fragmentsToAdd: FragmentDefinitionNode[] = [];
166166

167167
for (const fragmentName of missingFragments) {
@@ -218,9 +218,7 @@ const validationToRule = (
218218
create(context) {
219219
return {
220220
Document(node) {
221-
const schema = docs.requiresSchema
222-
? requireGraphQLSchemaFromContext(ruleId, context)
223-
: null;
221+
const schema = docs.requiresSchema ? requireGraphQLSchema(ruleId, context) : null;
224222

225223
const documentNode = getDocumentNode
226224
? getDocumentNode({ ruleId, context, node: node.rawNode() })
@@ -473,7 +471,7 @@ export const GRAPHQL_JS_VALIDATIONS: Record<string, GraphQLESLintRule> = Object.
473471
ruleId: 'no-unused-fragments',
474472
rule: NoUnusedFragmentsRule,
475473
getDocumentNode: ({ ruleId, context, node }) => {
476-
const siblings = requireSiblingsOperations(ruleId, context);
474+
const siblings = requireGraphQLOperations(ruleId, context);
477475
const FilePathToDocumentsMap = [
478476
...siblings.getOperations(),
479477
...siblings.getFragments(),

packages/plugin/src/rules/no-deprecated/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ArgumentNode, EnumValueNode, FieldNode, ObjectFieldNode } from 'graphql';
22
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
33
import { GraphQLESLintRule } from '../../types.js';
4-
import { displayNodeName, requireGraphQLSchemaFromContext } from '../../utils.js';
4+
import { displayNodeName, requireGraphQLSchema } from '../../utils.js';
55

66
const RULE_ID = 'no-deprecated';
77

@@ -84,7 +84,7 @@ export const rule: GraphQLESLintRule<[], true> = {
8484
schema: [],
8585
},
8686
create(context) {
87-
requireGraphQLSchemaFromContext(RULE_ID, context);
87+
requireGraphQLSchema(RULE_ID, context);
8888

8989
function report(
9090
node: GraphQLESTreeNode<EnumValueNode | FieldNode | ArgumentNode | ObjectFieldNode, true>,

packages/plugin/src/rules/no-one-place-fragments/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { relative } from 'node:path';
22
import { NameNode, visit } from 'graphql';
33
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
44
import { GraphQLESLintRule } from '../../types.js';
5-
import { CWD, requireSiblingsOperations } from '../../utils.js';
5+
import { CWD, requireGraphQLOperations } from '../../utils.js';
66

77
const RULE_ID = 'no-one-place-fragments';
88

@@ -54,7 +54,7 @@ export const rule: GraphQLESLintRule = {
5454
schema: [],
5555
},
5656
create(context) {
57-
const operations = requireSiblingsOperations(RULE_ID, context);
57+
const operations = requireGraphQLOperations(RULE_ID, context);
5858
const allDocuments = [...operations.getOperations(), ...operations.getFragments()];
5959

6060
const usedFragmentsMap: Record<string, string[]> = Object.create(null);

packages/plugin/src/rules/no-root-type/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { NameNode } from 'graphql';
22
import { FromSchema } from 'json-schema-to-ts';
33
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
44
import { GraphQLESLintRule } from '../../types.js';
5-
import { ARRAY_DEFAULT_OPTIONS, requireGraphQLSchemaFromContext, truthy } from '../../utils.js';
5+
import { ARRAY_DEFAULT_OPTIONS, requireGraphQLSchema, truthy } from '../../utils.js';
66

77
const schema = {
88
type: 'array',
@@ -59,7 +59,7 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
5959
schema,
6060
},
6161
create(context) {
62-
const schema = requireGraphQLSchemaFromContext('no-root-type', context);
62+
const schema = requireGraphQLSchema('no-root-type', context);
6363
const disallow = new Set(context.options[0].disallow);
6464

6565
const rootTypeNames = [

packages/plugin/src/rules/no-scalar-result-type-on-mutation/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isScalarType, Kind, NameNode } from 'graphql';
22
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
33
import { GraphQLESLintRule } from '../../types.js';
4-
import { getNodeName, requireGraphQLSchemaFromContext } from '../../utils.js';
4+
import { getNodeName, requireGraphQLSchema } from '../../utils.js';
55

66
const RULE_ID = 'no-scalar-result-type-on-mutation';
77

@@ -37,7 +37,7 @@ export const rule: GraphQLESLintRule = {
3737
schema: [],
3838
},
3939
create(context) {
40-
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
40+
const schema = requireGraphQLSchema(RULE_ID, context);
4141
const mutationType = schema.getMutationType();
4242
if (!mutationType) {
4343
return {};

packages/plugin/src/rules/no-unreachable-types/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import lowerCase from 'lodash.lowercase';
1414
import { ModuleCache } from '../../cache.js';
1515
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
1616
import { GraphQLESLintRule } from '../../types.js';
17-
import { getTypeName, requireGraphQLSchemaFromContext } from '../../utils.js';
17+
import { getTypeName, requireGraphQLSchema } from '../../utils.js';
1818

1919
const RULE_ID = 'no-unreachable-types';
2020

@@ -156,7 +156,7 @@ export const rule: GraphQLESLintRule = {
156156
hasSuggestions: true,
157157
},
158158
create(context) {
159-
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
159+
const schema = requireGraphQLSchema(RULE_ID, context);
160160
const reachableTypes = getReachableTypes(schema);
161161

162162
return {

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

+3-3
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 { requireGraphQLSchemaFromContext, requireSiblingsOperations } from '../../utils.js';
7+
import { requireGraphQLOperations, requireGraphQLSchema } from '../../utils.js';
88

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

@@ -214,8 +214,8 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
214214
hasSuggestions: true,
215215
},
216216
create(context) {
217-
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
218-
const siblingsOperations = requireSiblingsOperations(RULE_ID, context);
217+
const schema = requireGraphQLSchema(RULE_ID, context);
218+
const siblingsOperations = requireGraphQLOperations(RULE_ID, context);
219219
const usedFields = getUsedFields(schema, siblingsOperations);
220220
const { ignoredFieldSelectors } = context.options[0] || {};
221221
const selector = (ignoredFieldSelectors || []).reduce(

packages/plugin/src/rules/relay-arguments/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { FieldDefinitionNode, isScalarType, Kind, NameNode } from 'graphql';
22
import { FromSchema } from 'json-schema-to-ts';
33
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
44
import { GraphQLESLintRule } from '../../types.js';
5-
import { requireGraphQLSchemaFromContext } from '../../utils.js';
5+
import { requireGraphQLSchema } from '../../utils.js';
66

77
const RULE_ID = 'relay-arguments';
88
const MISSING_ARGUMENTS = 'MISSING_ARGUMENTS';
@@ -74,7 +74,7 @@ export const rule: GraphQLESLintRule<RuleOptions, true> = {
7474
schema,
7575
},
7676
create(context) {
77-
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
77+
const schema = requireGraphQLSchema(RULE_ID, context);
7878
const { includeBoth = true } = context.options[0] || {};
7979

8080
return {

packages/plugin/src/rules/relay-edge-types/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { FromSchema } from 'json-schema-to-ts';
1313
import { getDocumentNodeFromSchema } from '@graphql-tools/utils';
1414
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
1515
import { GraphQLESLintRule, GraphQLESLintRuleListener } from '../../types.js';
16-
import { getTypeName, requireGraphQLSchemaFromContext } from '../../utils.js';
16+
import { getTypeName, requireGraphQLSchema } from '../../utils.js';
1717

1818
const RULE_ID = 'relay-edge-types';
1919
const MESSAGE_MUST_BE_OBJECT_TYPE = 'MESSAGE_MUST_BE_OBJECT_TYPE';
@@ -124,7 +124,7 @@ export const rule: GraphQLESLintRule<RuleOptions, true> = {
124124
schema,
125125
},
126126
create(context) {
127-
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
127+
const schema = requireGraphQLSchema(RULE_ID, context);
128128
const edgeTypes = getEdgeTypes(schema);
129129
const options: RuleOptions[0] = {
130130
withEdgeSuffix: true,

packages/plugin/src/rules/relay-page-info/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isScalarType, Kind, NameNode, ObjectTypeDefinitionNode } from 'graphql';
22
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
33
import { GraphQLESLintRule } from '../../types.js';
4-
import { REPORT_ON_FIRST_CHARACTER, requireGraphQLSchemaFromContext } from '../../utils.js';
4+
import { REPORT_ON_FIRST_CHARACTER, requireGraphQLSchema } from '../../utils.js';
55
import { NON_OBJECT_TYPES } from '../relay-connection-types/index.js';
66

77
const RULE_ID = 'relay-page-info';
@@ -48,7 +48,7 @@ export const rule: GraphQLESLintRule = {
4848
schema: [],
4949
},
5050
create(context) {
51-
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
51+
const schema = requireGraphQLSchema(RULE_ID, context);
5252
if (process.env.NODE_ENV === 'test' || !hasPageInfoChecked) {
5353
const pageInfoType = schema.getType('PageInfo');
5454
if (!pageInfoType) {

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

+2-7
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ import { ASTKindToNode, Kind, TokenKind } from 'graphql';
22
import { getRootTypeNames } from '@graphql-tools/utils';
33
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
44
import { GraphQLESLintRule, ValueOf } from '../../types.js';
5-
import {
6-
getLocation,
7-
getNodeName,
8-
requireGraphQLSchemaFromContext,
9-
TYPES_KINDS,
10-
} from '../../utils.js';
5+
import { getLocation, getNodeName, requireGraphQLSchema, TYPES_KINDS } from '../../utils.js';
116

127
export const RULE_ID = 'require-description';
138

@@ -149,7 +144,7 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
149144
}
150145

151146
if (rootField) {
152-
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
147+
const schema = requireGraphQLSchema(RULE_ID, context);
153148
const rootTypeNames = getRootTypeNames(schema);
154149
kinds.add(
155150
`:matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=/^(${[

packages/plugin/src/rules/require-field-of-type-query-in-mutation-result/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isObjectType, NameNode, ObjectTypeDefinitionNode } from 'graphql';
22
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
33
import { GraphQLESLintRule } from '../../types.js';
4-
import { getTypeName, requireGraphQLSchemaFromContext } from '../../utils.js';
4+
import { getTypeName, requireGraphQLSchema } from '../../utils.js';
55

66
const RULE_ID = 'require-field-of-type-query-in-mutation-result';
77

@@ -47,7 +47,7 @@ export const rule: GraphQLESLintRule = {
4747
schema: [],
4848
},
4949
create(context) {
50-
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
50+
const schema = requireGraphQLSchema(RULE_ID, context);
5151
const mutationType = schema.getMutationType();
5252
const queryType = schema.getQueryType();
5353

packages/plugin/src/rules/require-import-fragment/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from 'node:path';
22
import { NameNode } from 'graphql';
33
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
44
import { GraphQLESLintRule } from '../../types.js';
5-
import { requireSiblingsOperations, slash } from '../../utils.js';
5+
import { requireGraphQLOperations, slash } from '../../utils.js';
66

77
const RULE_ID = 'require-import-fragment';
88
const SUGGESTION_ID = 'add-import-expression';
@@ -70,7 +70,7 @@ export const rule: GraphQLESLintRule = {
7070
},
7171
create(context) {
7272
const comments = context.getSourceCode().getAllComments();
73-
const siblings = requireSiblingsOperations(RULE_ID, context);
73+
const siblings = requireGraphQLOperations(RULE_ID, context);
7474
const filePath = context.filename;
7575

7676
return {

packages/plugin/src/rules/require-nullable-result-in-root/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Kind, ObjectTypeDefinitionNode } from 'graphql';
22
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
33
import { GraphQLESLintRule } from '../../types.js';
4-
import { getNodeName, requireGraphQLSchemaFromContext, truthy } from '../../utils.js';
4+
import { getNodeName, requireGraphQLSchema, truthy } from '../../utils.js';
55

66
const RULE_ID = 'require-nullable-result-in-root';
77

@@ -41,7 +41,7 @@ export const rule: GraphQLESLintRule = {
4141
schema: [],
4242
},
4343
create(context) {
44-
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
44+
const schema = requireGraphQLSchema(RULE_ID, context);
4545
const rootTypeNames = new Set(
4646
[schema.getQueryType(), schema.getMutationType()].filter(truthy).map(type => type.name),
4747
);

packages/plugin/src/rules/require-selections/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import { GraphQLESLintRule, OmitRecursively, ReportDescriptor } from '../../type
1818
import {
1919
ARRAY_DEFAULT_OPTIONS,
2020
englishJoinWords,
21-
requireGraphQLSchemaFromContext,
22-
requireSiblingsOperations,
21+
requireGraphQLOperations,
22+
requireGraphQLSchema,
2323
} from '../../utils.js';
2424

2525
const RULE_ID = 'require-selections';
@@ -113,8 +113,8 @@ export const rule: GraphQLESLintRule<RuleOptions, true> = {
113113
schema,
114114
},
115115
create(context) {
116-
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
117-
const siblings = requireSiblingsOperations(RULE_ID, context);
116+
const schema = requireGraphQLSchema(RULE_ID, context);
117+
const siblings = requireGraphQLOperations(RULE_ID, context);
118118
const { fieldName = DEFAULT_ID_FIELD_NAME } = context.options[0] || {};
119119
const idNames = asArray(fieldName);
120120

packages/plugin/src/rules/selection-set-depth/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { FromSchema } from 'json-schema-to-ts';
55
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
66
import { SiblingOperations } from '../../siblings.js';
77
import { GraphQLESLintRule } from '../../types.js';
8-
import { ARRAY_DEFAULT_OPTIONS, logger, requireSiblingsOperations } from '../../utils.js';
8+
import { ARRAY_DEFAULT_OPTIONS, logger, requireGraphQLOperations } from '../../utils.js';
99

1010
const RULE_ID = 'selection-set-depth';
1111

@@ -88,7 +88,7 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
8888
let siblings: SiblingOperations | null = null;
8989

9090
try {
91-
siblings = requireSiblingsOperations(RULE_ID, context);
91+
siblings = requireGraphQLOperations(RULE_ID, context);
9292
} catch {
9393
logger.warn(
9494
`Rule "${RULE_ID}" works best with siblings operations loaded. See https://the-guild.dev/graphql/eslint/docs/usage#providing-operations for more info`,

packages/plugin/src/rules/strict-id-in-types/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
ARRAY_DEFAULT_OPTIONS,
77
displayNodeName,
88
englishJoinWords,
9-
requireGraphQLSchemaFromContext,
9+
requireGraphQLSchema,
1010
truthy,
1111
} from '../../utils.js';
1212

@@ -131,7 +131,7 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
131131
...context.options[0],
132132
};
133133

134-
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
134+
const schema = requireGraphQLSchema(RULE_ID, context);
135135
const rootTypeNames = [
136136
schema.getQueryType(),
137137
schema.getMutationType(),

packages/plugin/src/rules/unique-fragment-name/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ExecutableDefinitionNode, Kind } from 'graphql';
33
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
44
import { FragmentSource, OperationSource } from '../../siblings.js';
55
import { GraphQLESLintRule, GraphQLESLintRuleContext } from '../../types.js';
6-
import { CWD, requireSiblingsOperations, slash, VIRTUAL_DOCUMENT_REGEX } from '../../utils.js';
6+
import { CWD, requireGraphQLOperations, slash, VIRTUAL_DOCUMENT_REGEX } from '../../utils.js';
77

88
const RULE_ID = 'unique-fragment-name';
99

@@ -13,7 +13,7 @@ export const checkNode = (
1313
ruleId: string,
1414
): void => {
1515
const documentName = node.name!.value;
16-
const siblings = requireSiblingsOperations(ruleId, context);
16+
const siblings = requireGraphQLOperations(ruleId, context);
1717
const siblingDocuments: (FragmentSource | OperationSource)[] =
1818
node.kind === Kind.FRAGMENT_DEFINITION
1919
? siblings.getFragment(documentName)

packages/plugin/src/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { GraphQLESTreeNode } from './estree-converter/index.js';
66
import { SiblingOperations } from './siblings.js';
77
import { GraphQLESLintRuleContext } from './types.js';
88

9-
export function requireSiblingsOperations(
9+
export function requireGraphQLOperations(
1010
ruleId: string,
1111
context: GraphQLESLintRuleContext,
1212
): SiblingOperations | never {
@@ -19,7 +19,7 @@ export function requireSiblingsOperations(
1919
return siblingOperations;
2020
}
2121

22-
export function requireGraphQLSchemaFromContext(
22+
export function requireGraphQLSchema(
2323
ruleId: string,
2424
context: GraphQLESLintRuleContext,
2525
): GraphQLSchema | never {

0 commit comments

Comments
 (0)