Skip to content

Commit

Permalink
fix(diag): directive miss report with multiple documents (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Apr 16, 2024
1 parent 45fe661 commit bc0f9cf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/six-chefs-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@0no-co/graphqlsp': patch
---

Fix directives being misreported due to globally declared regex maintaining state
4 changes: 1 addition & 3 deletions packages/graphqlsp/src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ const clientDirectives = new Set([
'inline',
]);

const directiveRegex = /Unknown directive "@([^)]+)"/g;

export const SEMANTIC_DIAGNOSTIC_CODE = 52001;
export const MISSING_OPERATION_NAME_CODE = 52002;
export const USING_DEPRECATED_FIELD_CODE = 52004;
Expand Down Expand Up @@ -385,7 +383,7 @@ const runDiagnostics = (
if (!diag.message.includes('Unknown directive')) return true;

const [message] = diag.message.split('(');
const matches = directiveRegex.exec(message);
const matches = /Unknown directive "@([^)]+)"/g.exec(message);
if (!matches) return true;
const directiveNmae = matches[1];
return !clientDirectives.has(directiveNmae);
Expand Down

0 comments on commit bc0f9cf

Please sign in to comment.