Skip to content

Commit

Permalink
fix loading ESM graphql.config.js configs, pattern too long error…
Browse files Browse the repository at this point in the history
… and rename flat configs (#2468)

* aa

* aa

* f11x

* fix playground
  • Loading branch information
dimaMachina authored Aug 3, 2024
1 parent da608d7 commit 733a66e
Show file tree
Hide file tree
Showing 14 changed files with 71 additions and 67 deletions.
22 changes: 22 additions & 0 deletions .changeset/friendly-singers-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@graphql-eslint/eslint-plugin': patch
---

- rename flat configs exports

```diff
-graphql.flatConfigs['schema-recommended']
+graphql.configs['flat/schema-recommended']
-graphql.flatConfigs['schema-relay']
+graphql.configs['flat/schema-relay']
-graphql.flatConfigs['schema-all']
+graphql.configs['flat/schema-all']
-graphql.flatConfigs['operations-recommended']
+graphql.configs['flat/operations-recommended']
-graphql.flatConfigs['operations-all']
+graphql.configs['flat/operations-all']
```

- fix with programmatic usage when passing large schema as string causes `pattern too long` error

- fix loading ESM `graphql.config.js` configs
6 changes: 3 additions & 3 deletions examples/code-file/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export default [
},
{
files: ['**/*.graphql'],
plugins: {
'@graphql-eslint': { rules: graphql.rules },
},
languageOptions: {
parser: graphql.parser,
},
plugins: {
'@graphql-eslint': { rules: graphql.rules },
},
rules: {
'@graphql-eslint/no-anonymous-operations': 'error',
'@graphql-eslint/naming-convention': [
Expand Down
6 changes: 3 additions & 3 deletions examples/graphql-config/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export default [
},
{
files: ['**/*.graphql'],
plugins: {
'@graphql-eslint': { rules: graphql.rules },
},
languageOptions: {
parser: graphql.parser,
},
plugins: {
'@graphql-eslint': { rules: graphql.rules },
},
rules: {
'@graphql-eslint/no-anonymous-operations': 'error',
'@graphql-eslint/no-duplicate-fields': 'error',
Expand Down
10 changes: 5 additions & 5 deletions examples/monorepo/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ export default [
{
// Setup GraphQL Parser
files: ['**/*.{graphql,gql}'],
plugins: {
'@graphql-eslint': { rules: graphql.rules },
},
languageOptions: {
parser: graphql.parser,
},
plugins: {
'@graphql-eslint': { rules: graphql.rules },
},
},
{
// Setup recommended config for schema files
files: [SCHEMA_PATH],
...graphql.flatConfigs['schema-recommended'],
rules: graphql.configs['flat/schema-recommended'],
},
{
// Setup recommended config for operations files
files: ['client/**/*.{graphql,gql}'],
...graphql.flatConfigs['operations-recommended'],
rules: graphql.configs['flat/operations-recommended'],
},
];
10 changes: 5 additions & 5 deletions examples/multiple-projects-graphql-config/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ export default [
{
// Setup GraphQL Parser
files: ['**/*.graphql'],
plugins: {
'@graphql-eslint': { rules: graphql.rules },
},
languageOptions: {
parser: graphql.parser,
},
plugins: {
'@graphql-eslint': { rules: graphql.rules },
},
},
{
files: ['schema.*.graphql'],
rules: {
...graphql.flatConfigs['schema-recommended'].rules,
...graphql.configs['flat/schema-recommended'],
'@graphql-eslint/require-description': 'off',
},
},
{
files: ['**/*.js/*.graphql'],
rules: graphql.flatConfigs['operations-recommended'].rules,
rules: graphql.configs['flat/operations-recommended'],
},
];
6 changes: 3 additions & 3 deletions examples/programmatic/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ export default [
},
{
files: ['**/*.graphql'],
plugins: {
'@graphql-eslint': { rules: graphql.rules },
},
languageOptions: {
parser: graphql.parser,
parserOptions: {
Expand All @@ -20,6 +17,9 @@ export default [
},
},
},
plugins: {
'@graphql-eslint': { rules: graphql.rules },
},
rules: {
'@graphql-eslint/require-selections': ['error', { fieldName: '_id' }],
'@graphql-eslint/unique-fragment-name': 'error',
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@graphql-tools/utils": "^10.0.0",
"debug": "^4.3.4",
"fast-glob": "^3.2.12",
"graphql-config": "^5.0.0",
"graphql-config": "^5.1.0",
"graphql-depth-limit": "^1.1.0",
"lodash.lowercase": "^4.3.0"
},
Expand Down
6 changes: 6 additions & 0 deletions packages/plugin/src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ export class ModuleCache<K, T> {
map = new Map<K, { lastSeen: [number, number]; result: T }>();

set(cacheKey: K, result: T): void {
// Remove server-side cache code in browser
if (typeof window !== 'undefined') return;

this.map.set(cacheKey, { lastSeen: process.hrtime(), result });
log('setting entry for', cacheKey);
}

get(cacheKey: K, settings = { lifetime: 10 /* seconds */ }): T | void {
// Remove server-side cache code in browser
if (typeof window !== 'undefined') return;

const value = this.map.get(cacheKey);
if (!value) {
log('cache miss for', cacheKey);
Expand Down
13 changes: 12 additions & 1 deletion packages/plugin/src/configs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@ export const configs = {
'schema-relay': relayConfig,
'operations-recommended': operationsRecommendedConfig,
'operations-all': operationsAllConfig,
} satisfies Record<ConfigName, unknown>;
'flat/schema-recommended': schemaRecommendedConfig.rules,
'flat/schema-all': {
...schemaRecommendedConfig.rules,
...schemaAllConfig.rules,
},
'flat/schema-relay': relayConfig.rules,
'flat/operations-recommended': operationsRecommendedConfig.rules,
'flat/operations-all': {
...operationsRecommendedConfig.rules,
...operationsAllConfig.rules,
},
} satisfies Record<ConfigName | `flat/${ConfigName}`, unknown>;
34 changes: 0 additions & 34 deletions packages/plugin/src/flat-configs.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/plugin/src/index.browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
export { parser } from './parser.js';
export { rules } from './rules/index.js';
export * from './types.js';
export { flatConfigs } from './flat-configs.js';
export { configs } from './configs/index.js';
1 change: 0 additions & 1 deletion packages/plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ export { requireGraphQLSchemaFromContext, requireSiblingsOperations } from './ut
export const processors = { graphql: processor };

export { configs } from './configs/index.js';
export { flatConfigs } from './flat-configs.js';
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions website/src/components/play-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { clsx } from 'clsx';
import { Linter } from 'eslint';
import debounce from 'lodash.debounce';
import { StringParam, useQueryParam, withDefault } from 'use-query-params';
import { ConfigName, flatConfigs, parser, rules } from '@graphql-eslint/eslint-plugin';
import { ConfigName, configs, parser, rules } from '@graphql-eslint/eslint-plugin';
import { asArray } from '@graphql-tools/utils';
import { GraphQLEditor } from './graphql-editor';
import { Select } from './select';
Expand Down Expand Up @@ -163,10 +163,10 @@ export function PlayPage(): ReactElement {
documents={operation}
selectedRules={{
// @ts-expect-error -- TODO: fix type error
...(schemaConfig && flatConfigs[schemaConfig].rules),
...(schemaConfig && configs[`flat/${schemaConfig}`]),
...(schemaRule && {
[`@graphql-eslint/${schemaRule}`]:
flatConfigs['schema-all'].rules[`@graphql-eslint/${schemaRule}`],
configs['flat/schema-all'][`@graphql-eslint/${schemaRule}`],
}),
}}
onChange={setSchema}
Expand All @@ -179,10 +179,10 @@ export function PlayPage(): ReactElement {
documents={operation}
selectedRules={{
// @ts-expect-error -- TODO: fix type error
...(operationConfig && flatConfigs[operationConfig].rules),
...(operationConfig && configs[`flat/${operationConfig}`]),
...(operationRule && {
[`@graphql-eslint/${operationRule}`]:
flatConfigs['operations-all'].rules[`@graphql-eslint/${operationRule}`],
configs['flat/operations-all'][`@graphql-eslint/${operationRule}`],
}),
}}
onChange={setOperation}
Expand Down

0 comments on commit 733a66e

Please sign in to comment.