Skip to content

Commit 733a66e

Browse files
authored
fix loading ESM graphql.config.js configs, pattern too long error and rename flat configs (#2468)
* aa * aa * f11x * fix playground
1 parent da608d7 commit 733a66e

File tree

14 files changed

+71
-67
lines changed

14 files changed

+71
-67
lines changed

.changeset/friendly-singers-rush.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': patch
3+
---
4+
5+
- rename flat configs exports
6+
7+
```diff
8+
-graphql.flatConfigs['schema-recommended']
9+
+graphql.configs['flat/schema-recommended']
10+
-graphql.flatConfigs['schema-relay']
11+
+graphql.configs['flat/schema-relay']
12+
-graphql.flatConfigs['schema-all']
13+
+graphql.configs['flat/schema-all']
14+
-graphql.flatConfigs['operations-recommended']
15+
+graphql.configs['flat/operations-recommended']
16+
-graphql.flatConfigs['operations-all']
17+
+graphql.configs['flat/operations-all']
18+
```
19+
20+
- fix with programmatic usage when passing large schema as string causes `pattern too long` error
21+
22+
- fix loading ESM `graphql.config.js` configs

examples/code-file/eslint.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ export default [
1212
},
1313
{
1414
files: ['**/*.graphql'],
15-
plugins: {
16-
'@graphql-eslint': { rules: graphql.rules },
17-
},
1815
languageOptions: {
1916
parser: graphql.parser,
2017
},
18+
plugins: {
19+
'@graphql-eslint': { rules: graphql.rules },
20+
},
2121
rules: {
2222
'@graphql-eslint/no-anonymous-operations': 'error',
2323
'@graphql-eslint/naming-convention': [

examples/graphql-config/eslint.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ export default [
88
},
99
{
1010
files: ['**/*.graphql'],
11-
plugins: {
12-
'@graphql-eslint': { rules: graphql.rules },
13-
},
1411
languageOptions: {
1512
parser: graphql.parser,
1613
},
14+
plugins: {
15+
'@graphql-eslint': { rules: graphql.rules },
16+
},
1717
rules: {
1818
'@graphql-eslint/no-anonymous-operations': 'error',
1919
'@graphql-eslint/no-duplicate-fields': 'error',

examples/monorepo/eslint.config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ export default [
2323
{
2424
// Setup GraphQL Parser
2525
files: ['**/*.{graphql,gql}'],
26-
plugins: {
27-
'@graphql-eslint': { rules: graphql.rules },
28-
},
2926
languageOptions: {
3027
parser: graphql.parser,
3128
},
29+
plugins: {
30+
'@graphql-eslint': { rules: graphql.rules },
31+
},
3232
},
3333
{
3434
// Setup recommended config for schema files
3535
files: [SCHEMA_PATH],
36-
...graphql.flatConfigs['schema-recommended'],
36+
rules: graphql.configs['flat/schema-recommended'],
3737
},
3838
{
3939
// Setup recommended config for operations files
4040
files: ['client/**/*.{graphql,gql}'],
41-
...graphql.flatConfigs['operations-recommended'],
41+
rules: graphql.configs['flat/operations-recommended'],
4242
},
4343
];

examples/multiple-projects-graphql-config/eslint.config.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ export default [
1010
{
1111
// Setup GraphQL Parser
1212
files: ['**/*.graphql'],
13-
plugins: {
14-
'@graphql-eslint': { rules: graphql.rules },
15-
},
1613
languageOptions: {
1714
parser: graphql.parser,
1815
},
16+
plugins: {
17+
'@graphql-eslint': { rules: graphql.rules },
18+
},
1919
},
2020
{
2121
files: ['schema.*.graphql'],
2222
rules: {
23-
...graphql.flatConfigs['schema-recommended'].rules,
23+
...graphql.configs['flat/schema-recommended'],
2424
'@graphql-eslint/require-description': 'off',
2525
},
2626
},
2727
{
2828
files: ['**/*.js/*.graphql'],
29-
rules: graphql.flatConfigs['operations-recommended'].rules,
29+
rules: graphql.configs['flat/operations-recommended'],
3030
},
3131
];

examples/programmatic/eslint.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ export default [
88
},
99
{
1010
files: ['**/*.graphql'],
11-
plugins: {
12-
'@graphql-eslint': { rules: graphql.rules },
13-
},
1411
languageOptions: {
1512
parser: graphql.parser,
1613
parserOptions: {
@@ -20,6 +17,9 @@ export default [
2017
},
2118
},
2219
},
20+
plugins: {
21+
'@graphql-eslint': { rules: graphql.rules },
22+
},
2323
rules: {
2424
'@graphql-eslint/require-selections': ['error', { fieldName: '_id' }],
2525
'@graphql-eslint/unique-fragment-name': 'error',

packages/plugin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"@graphql-tools/utils": "^10.0.0",
5050
"debug": "^4.3.4",
5151
"fast-glob": "^3.2.12",
52-
"graphql-config": "^5.0.0",
52+
"graphql-config": "^5.1.0",
5353
"graphql-depth-limit": "^1.1.0",
5454
"lodash.lowercase": "^4.3.0"
5555
},

packages/plugin/src/cache.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ export class ModuleCache<K, T> {
88
map = new Map<K, { lastSeen: [number, number]; result: T }>();
99

1010
set(cacheKey: K, result: T): void {
11+
// Remove server-side cache code in browser
12+
if (typeof window !== 'undefined') return;
13+
1114
this.map.set(cacheKey, { lastSeen: process.hrtime(), result });
1215
log('setting entry for', cacheKey);
1316
}
1417

1518
get(cacheKey: K, settings = { lifetime: 10 /* seconds */ }): T | void {
19+
// Remove server-side cache code in browser
20+
if (typeof window !== 'undefined') return;
21+
1622
const value = this.map.get(cacheKey);
1723
if (!value) {
1824
log('cache miss for', cacheKey);

packages/plugin/src/configs/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,15 @@ export const configs = {
1616
'schema-relay': relayConfig,
1717
'operations-recommended': operationsRecommendedConfig,
1818
'operations-all': operationsAllConfig,
19-
} satisfies Record<ConfigName, unknown>;
19+
'flat/schema-recommended': schemaRecommendedConfig.rules,
20+
'flat/schema-all': {
21+
...schemaRecommendedConfig.rules,
22+
...schemaAllConfig.rules,
23+
},
24+
'flat/schema-relay': relayConfig.rules,
25+
'flat/operations-recommended': operationsRecommendedConfig.rules,
26+
'flat/operations-all': {
27+
...operationsRecommendedConfig.rules,
28+
...operationsAllConfig.rules,
29+
},
30+
} satisfies Record<ConfigName | `flat/${ConfigName}`, unknown>;

packages/plugin/src/flat-configs.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)