Skip to content

Commit eab5492

Browse files
authored
fix race condition of loading graphql-config (#1165)
1 parent b12da39 commit eab5492

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

.changeset/nice-drinks-sin.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 race condition of `loadGraphQLConfig()`

packages/plugin/src/processor.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,34 @@ export type Block = Linter.ProcessorFile & {
88
offset: number;
99
};
1010

11-
const graphQLTagPluckOptions: GraphQLTagPluckOptions =
12-
loadGraphQLConfig().getDefault()?.extensions?.graphqlTagPluck;
13-
14-
const {
15-
modules = [],
16-
globalGqlIdentifierName = ['gql', 'graphql'],
17-
gqlMagicComment = 'GraphQL',
18-
} = graphQLTagPluckOptions || {};
19-
20-
const RELEVANT_KEYWORDS = [
21-
...new Set(
22-
[
23-
...modules.map(({ identifier }) => identifier),
24-
...asArray(globalGqlIdentifierName),
25-
gqlMagicComment,
26-
].filter(Boolean)
27-
),
28-
];
11+
let RELEVANT_KEYWORDS: string[];
12+
let graphQLTagPluckOptions: GraphQLTagPluckOptions;
2913

3014
const blocksMap = new Map<string, Block[]>();
3115

3216
export const processor: Linter.Processor<Block | string> = {
3317
supportsAutofix: true,
3418
preprocess(code, filePath) {
19+
if (!RELEVANT_KEYWORDS) {
20+
graphQLTagPluckOptions = loadGraphQLConfig().getDefault()?.extensions?.graphqlTagPluck;
21+
22+
const {
23+
modules = [],
24+
globalGqlIdentifierName = ['gql', 'graphql'],
25+
gqlMagicComment = 'GraphQL',
26+
} = graphQLTagPluckOptions || {};
27+
28+
RELEVANT_KEYWORDS = [
29+
...new Set(
30+
[
31+
...modules.map(({ identifier }) => identifier),
32+
...asArray(globalGqlIdentifierName),
33+
gqlMagicComment,
34+
].filter(Boolean)
35+
),
36+
];
37+
}
38+
3539
if (RELEVANT_KEYWORDS.every(keyword => !code.includes(keyword))) {
3640
return [code];
3741
}

packages/plugin/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export type RuleDocsInfo<T> = {
7777
export type GraphQLESLintRule<Options = any[], WithTypeInfo extends boolean = false> = {
7878
create(context: GraphQLESLintRuleContext<Options>): GraphQLESLintRuleListener<WithTypeInfo>;
7979
meta: Omit<Rule.RuleMetaData, 'docs'> & {
80-
docs: RuleDocsInfo<Options>
80+
docs: RuleDocsInfo<Options>;
8181
};
8282
};
8383

0 commit comments

Comments
 (0)