Skip to content

GraphQLESLintRule.meta.schema type issue #2914

Open
@michaelfaith

Description

@michaelfaith

Issue workflow progress

Progress of the issue based on the
Contributor Workflow

  • 1. The issue provides a reproduction available on GitHub, Stackblitz or CodeSandbox

    For example, you can start off by editing the
    'basic' example on Stackblitz.

    Please make sure the graphql-eslint version under package.json matches yours.

  • 2. A failing test has been provided

  • 3. A local solution has been provided

  • 4. A pull request is pending review


Describe the bug

The current type for meta.schema under the Rule type results in a typescript error when using strict type checking, and providing an array.

Image

If I change it to an object instead of an array, the type error goes away.

To Reproduce Steps to reproduce the behavior:

Expected behavior

Environment:

  • OS: MacOS
  • @graphql-eslint/eslint-plugin: 4.4.0
  • Node.js: 22.11

Additional context
I believe this is due to [] not having a relevant type on https://github.com/graphql-hive/graphql-eslint/blob/master/packages/plugin/src/types.ts#L79

Recommend something similar to

type GraphQLESLintRule<Options = [], WithTypeInfo extends boolean = false> = {
    meta: Omit<Rule.RuleMetaData, 'docs' | 'schema'> & {
        docs?: RuleDocsInfo<Options>;
-        schema: Readonly<JSONSchema> | [];
+        schema: Readonly<JSONSchema> | JSONSchema[];
    };
    create(context: GraphQLESLintRuleContext<Options>): GraphQLESLintRuleListener<WithTypeInfo>;
};

I tested the above locally, and it resolves the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions