graphql-eslint icon indicating copy to clipboard operation
graphql-eslint copied to clipboard

Passing large schema in as string causes pattern too long error

Open cernst11 opened this issue 1 year ago • 6 comments

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 editng 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

When passing a large schema of over 8kb as a string instead of file path the loader attempts to pattern match the raw string and will throw and eslint pattern too long error.

To Reproduce Steps to reproduce the behavior:

Programatically extend and call the ESLint class and load the schema as a string into parserOptions. Next use the lintText method of the class to lint the GraphQL schema subset against the entire schema. Here an error will be thrown about the pattern being too long.

An example can be found and ran here. To run the example in the terminal run npm start

From here the following error message will be displayed

[
  {
    ruleId: null,
    fatal: true,
    severity: 2,
    message: 'Parsing error: [graphql-eslint] pattern is too long',
    line: undefined,
    column: undefined,
    nodeType: null
  }
]

Environment:

  • OS: Linux/MacOS
  • @graphql-eslint/eslint-plugin: 3.20.1
  • Node.js:

Additional context

This appears to be worked around in version 4 of the linter here by building the schema differently in the browser for use in the playground.

cernst11 avatar Dec 01 '23 14:12 cernst11

Hi, could you create a reproduction, or share your schema?

dimaMachina avatar Dec 01 '23 14:12 dimaMachina

Hey @dimaMachina I am working on it, Accidentally submitted before wrapping up and I am editing it now

cernst11 avatar Dec 01 '23 14:12 cernst11

@dimaMachina I have updated the bug with a description. I will see if I can put a sandbox together as an example. Our schema cannot be shared but I think I can create a similar way to reproduce if it would help

cernst11 avatar Dec 01 '23 15:12 cernst11

@cernst11 thank you, some reproduction will be very helpful

dimaMachina avatar Dec 01 '23 21:12 dimaMachina

Hey @dimaMachina I have created an example here. I simplified our code down to the bare minimum and generated a mock schema. I have also updated the original description

cernst11 avatar Dec 04 '23 09:12 cernst11

@cernst11 so the error says Parsing error: [graphql-eslint] pattern is too long which goes from graphql-config's minimatch dependency

https://github.com/isaacs/minimatch/blob/ef8f2672bdbbf6a632ea815636659fb31b5169aa/src/assert-valid-pattern.ts#L1-L12

where value const MAX_PATTERN_LENGTH = 1024 * 64 is hardcoded to 65536, your schema SDL contains 73892 characters

We'll try to find a way to fix it!

dimaMachina avatar Dec 04 '23 19:12 dimaMachina