Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .changeset/sour-peaches-prove.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@graphql-eslint/eslint-plugin': major
---

- rename `requireSiblingsOperations` to `requireGraphQLOperations`
- rename `requireGraphQLSchemaFromContext` to `requireGraphQLSchema`
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ module.exports = {
files: ['website/**/*.mdx/**'],
rules: {
'import/no-default-export': 'off',
'no-dupe-keys': 'off', // Usage examples contains duplicate keys
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export * from './types.js';
export type { IGraphQLConfig } from 'graphql-config';
export type { GraphQLTagPluckOptions } from '@graphql-tools/graphql-tag-pluck';

export { requireGraphQLSchemaFromContext, requireSiblingsOperations } from './utils.js';
export { requireGraphQLSchema, requireGraphQLOperations } from './utils.js';

export const processors = { graphql: processor };

Expand Down
12 changes: 5 additions & 7 deletions packages/plugin/src/rules/graphql-js-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ import { GraphQLESLintRule, GraphQLESLintRuleContext, RuleDocsInfo } from '../ty
import {
ARRAY_DEFAULT_OPTIONS,
REPORT_ON_FIRST_CHARACTER,
requireGraphQLSchemaFromContext,
requireSiblingsOperations,
requireGraphQLOperations,
requireGraphQLSchema,
} from '../utils.js';

type GraphQLJSRule = ValidationRule | SDLValidationRule;
Expand Down Expand Up @@ -161,7 +161,7 @@ type GetDocumentNode = (props: {
const handleMissingFragments: GetDocumentNode = ({ ruleId, context, node }) => {
const missingFragments = getMissingFragments(node);
if (missingFragments.length > 0) {
const siblings = requireSiblingsOperations(ruleId, context);
const siblings = requireGraphQLOperations(ruleId, context);
const fragmentsToAdd: FragmentDefinitionNode[] = [];

for (const fragmentName of missingFragments) {
Expand Down Expand Up @@ -218,9 +218,7 @@ const validationToRule = (
create(context) {
return {
Document(node) {
const schema = docs.requiresSchema
? requireGraphQLSchemaFromContext(ruleId, context)
: null;
const schema = docs.requiresSchema ? requireGraphQLSchema(ruleId, context) : null;

const documentNode = getDocumentNode
? getDocumentNode({ ruleId, context, node: node.rawNode() })
Expand Down Expand Up @@ -473,7 +471,7 @@ export const GRAPHQL_JS_VALIDATIONS: Record<string, GraphQLESLintRule> = Object.
ruleId: 'no-unused-fragments',
rule: NoUnusedFragmentsRule,
getDocumentNode: ({ ruleId, context, node }) => {
const siblings = requireSiblingsOperations(ruleId, context);
const siblings = requireGraphQLOperations(ruleId, context);
const FilePathToDocumentsMap = [
...siblings.getOperations(),
...siblings.getFragments(),
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin/src/rules/no-deprecated/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ArgumentNode, EnumValueNode, FieldNode, ObjectFieldNode } from 'graphql';
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
import { GraphQLESLintRule } from '../../types.js';
import { displayNodeName, requireGraphQLSchemaFromContext } from '../../utils.js';
import { displayNodeName, requireGraphQLSchema } from '../../utils.js';

const RULE_ID = 'no-deprecated';

Expand Down Expand Up @@ -84,7 +84,7 @@ export const rule: GraphQLESLintRule<[], true> = {
schema: [],
},
create(context) {
requireGraphQLSchemaFromContext(RULE_ID, context);
requireGraphQLSchema(RULE_ID, context);

function report(
node: GraphQLESTreeNode<EnumValueNode | FieldNode | ArgumentNode | ObjectFieldNode, true>,
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin/src/rules/no-one-place-fragments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { relative } from 'node:path';
import { NameNode, visit } from 'graphql';
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
import { GraphQLESLintRule } from '../../types.js';
import { CWD, requireSiblingsOperations } from '../../utils.js';
import { CWD, requireGraphQLOperations } from '../../utils.js';

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

Expand Down Expand Up @@ -54,7 +54,7 @@ export const rule: GraphQLESLintRule = {
schema: [],
},
create(context) {
const operations = requireSiblingsOperations(RULE_ID, context);
const operations = requireGraphQLOperations(RULE_ID, context);
const allDocuments = [...operations.getOperations(), ...operations.getFragments()];

const usedFragmentsMap: Record<string, string[]> = Object.create(null);
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin/src/rules/no-root-type/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NameNode } from 'graphql';
import { FromSchema } from 'json-schema-to-ts';
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
import { GraphQLESLintRule } from '../../types.js';
import { ARRAY_DEFAULT_OPTIONS, requireGraphQLSchemaFromContext, truthy } from '../../utils.js';
import { ARRAY_DEFAULT_OPTIONS, requireGraphQLSchema, truthy } from '../../utils.js';

const schema = {
type: 'array',
Expand Down Expand Up @@ -59,7 +59,7 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
schema,
},
create(context) {
const schema = requireGraphQLSchemaFromContext('no-root-type', context);
const schema = requireGraphQLSchema('no-root-type', context);
const disallow = new Set(context.options[0].disallow);

const rootTypeNames = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isScalarType, Kind, NameNode } from 'graphql';
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
import { GraphQLESLintRule } from '../../types.js';
import { getNodeName, requireGraphQLSchemaFromContext } from '../../utils.js';
import { getNodeName, requireGraphQLSchema } from '../../utils.js';

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

Expand Down Expand Up @@ -37,7 +37,7 @@ export const rule: GraphQLESLintRule = {
schema: [],
},
create(context) {
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
const schema = requireGraphQLSchema(RULE_ID, context);
const mutationType = schema.getMutationType();
if (!mutationType) {
return {};
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin/src/rules/no-unreachable-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import lowerCase from 'lodash.lowercase';
import { ModuleCache } from '../../cache.js';
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
import { GraphQLESLintRule } from '../../types.js';
import { getTypeName, requireGraphQLSchemaFromContext } from '../../utils.js';
import { getTypeName, requireGraphQLSchema } from '../../utils.js';

const RULE_ID = 'no-unreachable-types';

Expand Down Expand Up @@ -156,7 +156,7 @@ export const rule: GraphQLESLintRule = {
hasSuggestions: true,
},
create(context) {
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
const schema = requireGraphQLSchema(RULE_ID, context);
const reachableTypes = getReachableTypes(schema);

return {
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin/src/rules/no-unused-fields/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FromSchema } from 'json-schema-to-ts';
import { ModuleCache } from '../../cache.js';
import { SiblingOperations } from '../../siblings.js';
import { GraphQLESLintRule, GraphQLESTreeNode } from '../../types.js';
import { requireGraphQLSchemaFromContext, requireSiblingsOperations } from '../../utils.js';
import { requireGraphQLOperations, requireGraphQLSchema } from '../../utils.js';

const RULE_ID = 'no-unused-fields';

Expand Down Expand Up @@ -214,8 +214,8 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
hasSuggestions: true,
},
create(context) {
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
const siblingsOperations = requireSiblingsOperations(RULE_ID, context);
const schema = requireGraphQLSchema(RULE_ID, context);
const siblingsOperations = requireGraphQLOperations(RULE_ID, context);
const usedFields = getUsedFields(schema, siblingsOperations);
const { ignoredFieldSelectors } = context.options[0] || {};
const selector = (ignoredFieldSelectors || []).reduce(
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin/src/rules/relay-arguments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FieldDefinitionNode, isScalarType, Kind, NameNode } from 'graphql';
import { FromSchema } from 'json-schema-to-ts';
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
import { GraphQLESLintRule } from '../../types.js';
import { requireGraphQLSchemaFromContext } from '../../utils.js';
import { requireGraphQLSchema } from '../../utils.js';

const RULE_ID = 'relay-arguments';
const MISSING_ARGUMENTS = 'MISSING_ARGUMENTS';
Expand Down Expand Up @@ -74,7 +74,7 @@ export const rule: GraphQLESLintRule<RuleOptions, true> = {
schema,
},
create(context) {
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
const schema = requireGraphQLSchema(RULE_ID, context);
const { includeBoth = true } = context.options[0] || {};

return {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin/src/rules/relay-edge-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { FromSchema } from 'json-schema-to-ts';
import { getDocumentNodeFromSchema } from '@graphql-tools/utils';
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
import { GraphQLESLintRule, GraphQLESLintRuleListener } from '../../types.js';
import { getTypeName, requireGraphQLSchemaFromContext } from '../../utils.js';
import { getTypeName, requireGraphQLSchema } from '../../utils.js';

const RULE_ID = 'relay-edge-types';
const MESSAGE_MUST_BE_OBJECT_TYPE = 'MESSAGE_MUST_BE_OBJECT_TYPE';
Expand Down Expand Up @@ -124,7 +124,7 @@ export const rule: GraphQLESLintRule<RuleOptions, true> = {
schema,
},
create(context) {
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
const schema = requireGraphQLSchema(RULE_ID, context);
const edgeTypes = getEdgeTypes(schema);
const options: RuleOptions[0] = {
withEdgeSuffix: true,
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin/src/rules/relay-page-info/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isScalarType, Kind, NameNode, ObjectTypeDefinitionNode } from 'graphql';
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
import { GraphQLESLintRule } from '../../types.js';
import { REPORT_ON_FIRST_CHARACTER, requireGraphQLSchemaFromContext } from '../../utils.js';
import { REPORT_ON_FIRST_CHARACTER, requireGraphQLSchema } from '../../utils.js';
import { NON_OBJECT_TYPES } from '../relay-connection-types/index.js';

const RULE_ID = 'relay-page-info';
Expand Down Expand Up @@ -48,7 +48,7 @@ export const rule: GraphQLESLintRule = {
schema: [],
},
create(context) {
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
const schema = requireGraphQLSchema(RULE_ID, context);
if (process.env.NODE_ENV === 'test' || !hasPageInfoChecked) {
const pageInfoType = schema.getType('PageInfo');
if (!pageInfoType) {
Expand Down
9 changes: 2 additions & 7 deletions packages/plugin/src/rules/require-description/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import { ASTKindToNode, Kind, TokenKind } from 'graphql';
import { getRootTypeNames } from '@graphql-tools/utils';
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
import { GraphQLESLintRule, ValueOf } from '../../types.js';
import {
getLocation,
getNodeName,
requireGraphQLSchemaFromContext,
TYPES_KINDS,
} from '../../utils.js';
import { getLocation, getNodeName, requireGraphQLSchema, TYPES_KINDS } from '../../utils.js';

export const RULE_ID = 'require-description';

Expand Down Expand Up @@ -149,7 +144,7 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
}

if (rootField) {
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
const schema = requireGraphQLSchema(RULE_ID, context);
const rootTypeNames = getRootTypeNames(schema);
kinds.add(
`:matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=/^(${[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isObjectType, NameNode, ObjectTypeDefinitionNode } from 'graphql';
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
import { GraphQLESLintRule } from '../../types.js';
import { getTypeName, requireGraphQLSchemaFromContext } from '../../utils.js';
import { getTypeName, requireGraphQLSchema } from '../../utils.js';

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

Expand Down Expand Up @@ -47,7 +47,7 @@ export const rule: GraphQLESLintRule = {
schema: [],
},
create(context) {
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
const schema = requireGraphQLSchema(RULE_ID, context);
const mutationType = schema.getMutationType();
const queryType = schema.getQueryType();

Expand Down
4 changes: 2 additions & 2 deletions packages/plugin/src/rules/require-import-fragment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'node:path';
import { NameNode } from 'graphql';
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
import { GraphQLESLintRule } from '../../types.js';
import { requireSiblingsOperations, slash } from '../../utils.js';
import { requireGraphQLOperations, slash } from '../../utils.js';

const RULE_ID = 'require-import-fragment';
const SUGGESTION_ID = 'add-import-expression';
Expand Down Expand Up @@ -70,7 +70,7 @@ export const rule: GraphQLESLintRule = {
},
create(context) {
const comments = context.getSourceCode().getAllComments();
const siblings = requireSiblingsOperations(RULE_ID, context);
const siblings = requireGraphQLOperations(RULE_ID, context);
const filePath = context.filename;

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Kind, ObjectTypeDefinitionNode } from 'graphql';
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
import { GraphQLESLintRule } from '../../types.js';
import { getNodeName, requireGraphQLSchemaFromContext, truthy } from '../../utils.js';
import { getNodeName, requireGraphQLSchema, truthy } from '../../utils.js';

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

Expand Down Expand Up @@ -41,7 +41,7 @@ export const rule: GraphQLESLintRule = {
schema: [],
},
create(context) {
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
const schema = requireGraphQLSchema(RULE_ID, context);
const rootTypeNames = new Set(
[schema.getQueryType(), schema.getMutationType()].filter(truthy).map(type => type.name),
);
Expand Down
8 changes: 4 additions & 4 deletions packages/plugin/src/rules/require-selections/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { GraphQLESLintRule, OmitRecursively, ReportDescriptor } from '../../type
import {
ARRAY_DEFAULT_OPTIONS,
englishJoinWords,
requireGraphQLSchemaFromContext,
requireSiblingsOperations,
requireGraphQLOperations,
requireGraphQLSchema,
} from '../../utils.js';

const RULE_ID = 'require-selections';
Expand Down Expand Up @@ -113,8 +113,8 @@ export const rule: GraphQLESLintRule<RuleOptions, true> = {
schema,
},
create(context) {
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
const siblings = requireSiblingsOperations(RULE_ID, context);
const schema = requireGraphQLSchema(RULE_ID, context);
const siblings = requireGraphQLOperations(RULE_ID, context);
const { fieldName = DEFAULT_ID_FIELD_NAME } = context.options[0] || {};
const idNames = asArray(fieldName);

Expand Down
4 changes: 2 additions & 2 deletions packages/plugin/src/rules/selection-set-depth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FromSchema } from 'json-schema-to-ts';
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
import { SiblingOperations } from '../../siblings.js';
import { GraphQLESLintRule } from '../../types.js';
import { ARRAY_DEFAULT_OPTIONS, logger, requireSiblingsOperations } from '../../utils.js';
import { ARRAY_DEFAULT_OPTIONS, logger, requireGraphQLOperations } from '../../utils.js';

const RULE_ID = 'selection-set-depth';

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

try {
siblings = requireSiblingsOperations(RULE_ID, context);
siblings = requireGraphQLOperations(RULE_ID, context);
} catch {
logger.warn(
`Rule "${RULE_ID}" works best with siblings operations loaded. See https://the-guild.dev/graphql/eslint/docs/usage#providing-operations for more info`,
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin/src/rules/strict-id-in-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ARRAY_DEFAULT_OPTIONS,
displayNodeName,
englishJoinWords,
requireGraphQLSchemaFromContext,
requireGraphQLSchema,
truthy,
} from '../../utils.js';

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

const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
const schema = requireGraphQLSchema(RULE_ID, context);
const rootTypeNames = [
schema.getQueryType(),
schema.getMutationType(),
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin/src/rules/unique-fragment-name/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ExecutableDefinitionNode, Kind } from 'graphql';
import { GraphQLESTreeNode } from '../../estree-converter/index.js';
import { FragmentSource, OperationSource } from '../../siblings.js';
import { GraphQLESLintRule, GraphQLESLintRuleContext } from '../../types.js';
import { CWD, requireSiblingsOperations, slash, VIRTUAL_DOCUMENT_REGEX } from '../../utils.js';
import { CWD, requireGraphQLOperations, slash, VIRTUAL_DOCUMENT_REGEX } from '../../utils.js';

const RULE_ID = 'unique-fragment-name';

Expand All @@ -13,7 +13,7 @@ export const checkNode = (
ruleId: string,
): void => {
const documentName = node.name!.value;
const siblings = requireSiblingsOperations(ruleId, context);
const siblings = requireGraphQLOperations(ruleId, context);
const siblingDocuments: (FragmentSource | OperationSource)[] =
node.kind === Kind.FRAGMENT_DEFINITION
? siblings.getFragment(documentName)
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { GraphQLESTreeNode } from './estree-converter/index.js';
import { SiblingOperations } from './siblings.js';
import { GraphQLESLintRuleContext } from './types.js';

export function requireSiblingsOperations(
export function requireGraphQLOperations(
ruleId: string,
context: GraphQLESLintRuleContext,
): SiblingOperations | never {
Expand All @@ -19,7 +19,7 @@ export function requireSiblingsOperations(
return siblingOperations;
}

export function requireGraphQLSchemaFromContext(
export function requireGraphQLSchema(
ruleId: string,
context: GraphQLESLintRuleContext,
): GraphQLSchema | never {
Expand Down
Loading
Loading