Skip to content

Commit 1517671

Browse files
authored
Merge pull request #63 from dotansimha/fix-graphql-v14
Fix compatibility with GraphQL v14
2 parents 6c445d6 + 2b87cb1 commit 1517671

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

.changeset/bright-clocks-relate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': patch
3+
---
4+
5+
Fix compatibility with GraphQL v14

packages/plugin/src/parser.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,24 @@ export function parse(code: string, options?: GraphQLParseOptions): Linter.ESLin
1818
return parseForESLint(code, options).ast;
1919
}
2020

21+
function getLexer(source: Source): Lexer {
22+
// GraphQL v14
23+
const gqlLanguage = require('graphql/language');
24+
if (gqlLanguage && gqlLanguage.createLexer) {
25+
return gqlLanguage.createLexer(source, {});
26+
}
27+
28+
// GraphQL v15
29+
const { Lexer: LexerCls } = require('graphql');
30+
if (LexerCls && typeof LexerCls === 'function') {
31+
return new LexerCls(source);
32+
}
33+
34+
throw new Error(`Unsupported GraphQL version! Please make sure to use GraphQL v14 or newer!`);
35+
}
36+
2137
export function extractTokens(source: string): AST.Token[] {
22-
const lexer = new Lexer(new Source(source));
38+
const lexer = getLexer(new Source(source));
2339
const tokens: AST.Token[] = [];
2440
let token = lexer.advance();
2541

0 commit comments

Comments
 (0)