Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap cm6-graphql lint logic in try..catch #3461

Merged
merged 2 commits into from
Nov 17, 2023
Merged

Conversation

imolorhe
Copy link
Contributor

It turns out that getDiagnostics may throw errors which codemirror 6 doesn't handle in the lint. Wrapping the logic in try..catch to handle errors and just return an empty array instead.

Copy link

changeset-bot bot commented Nov 16, 2023

🦋 Changeset detected

Latest commit: 54ebaeb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
cm6-graphql Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

codecov bot commented Nov 16, 2023

Codecov Report

Merging #3461 (54ebaeb) into main (2348641) will increase coverage by 0.10%.
Report is 28 commits behind head on main.
The diff coverage is 79.31%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3461      +/-   ##
==========================================
+ Coverage   55.75%   55.85%   +0.10%     
==========================================
  Files         110      110              
  Lines        5243     5264      +21     
  Branches     1426     1435       +9     
==========================================
+ Hits         2923     2940      +17     
- Misses       1897     1898       +1     
- Partials      423      426       +3     
Files Coverage Δ
packages/graphiql-react/src/editor/context.tsx 73.39% <100.00%> (ø)
...raphql-language-service-server/src/GraphQLCache.ts 50.88% <50.00%> (ø)
...ql-language-service-server/src/MessageProcessor.ts 46.11% <50.00%> (-0.11%) ⬇️
...nguage-service/src/utils/getVariablesJSONSchema.ts 94.59% <98.38%> (+0.71%) ⬆️
packages/graphiql/src/components/GraphiQL.tsx 68.96% <0.00%> (-0.97%) ⬇️
packages/graphiql-react/src/editor/hooks.ts 40.15% <23.52%> (+1.56%) ⬆️

Copy link
Contributor

github-actions bot commented Nov 16, 2023

The latest changes of this PR are available as canary in npm (based on the declared changesets):

cm6-graphql@0.0.11-canary-7efdaeb3.0

@imolorhe imolorhe requested a review from acao November 17, 2023 02:54
Copy link
Member

@acao acao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense for me! now I think i need to add this to our other mode, haha!

@imolorhe imolorhe merged commit 129666a into main Nov 17, 2023
14 checks passed
@imolorhe imolorhe deleted the imolorhe/try-catch-cm6-lint branch November 17, 2023 09:15
@acao acao mentioned this pull request Nov 17, 2023
@imolorhe
Copy link
Contributor Author

@acao I was thinking about this a bit more. The error that gets thrown is usually because of an invalid schema:

  • getDiagnostics() calls validate() in graphql
  • validate() throws an error if the schema is not valid

With this current try..catch, we are ignoring this type of error, which you can argue is fine since it's not a validation error in the GraphQL query (which the linter is meant for), but should we also report the invalid GraphQL schema from the linter as well? (The position of the error can just be line 1, col 1). I feel like that might be more useful to devs. We could also consider making devs choose the behavior they want here with a config option.

What do you think?

@acao
Copy link
Member

acao commented Nov 17, 2023

Hmm yeah, that makes a lot of sense to me!
Perhaps we can even write schema errors to an StateField? Or maybe that's not needed

@imolorhe
Copy link
Contributor Author

Yeah writing to a state field may not be needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants