From 1b683074349e11fe555253962ac55b623ef5479b Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Mon, 6 Mar 2023 20:28:02 +0100 Subject: [PATCH 01/13] setup rule --- .eslintrc.js | 9 ++++ package.json | 4 +- tsconfig.eslint.json | 25 ++++++++++ yarn.lock | 107 ++++++++++++++++++++++++++++++++----------- 4 files changed, 117 insertions(+), 28 deletions(-) create mode 100644 tsconfig.eslint.json diff --git a/.eslintrc.js b/.eslintrc.js index 90d4997b9b2..f8b20ac3cff 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -289,6 +289,15 @@ module.exports = { plugins: ['promise', 'sonarjs', 'unicorn'], overrides: [ + { + files: ['**/*.{ts,tsx}'], + rules: { + '@typescript-eslint/no-unnecessary-type-assertion': 'error', + }, + parserOptions: { + project: ['tsconfig.eslint.json'], + }, + }, // Cypress plugin, global, etc., only for cypress directory // https://github.com/cypress-io/eslint-plugin-cypress // cypress clashes with jest expect() diff --git a/package.json b/package.json index d21889cf1c4..1c25a37b2f6 100644 --- a/package.json +++ b/package.json @@ -105,8 +105,8 @@ "@types/react": "^17.0.37", "@types/react-dom": "^17.0.17", "@types/ws": "^7.4.0", - "@typescript-eslint/eslint-plugin": "^5.27.0", - "@typescript-eslint/parser": "^5.27.0", + "@typescript-eslint/eslint-plugin": "^5.54.1", + "@typescript-eslint/parser": "^5.54.1", "aws-serverless-express": "^3.4.0", "babel-jest": "^29.4.3", "concurrently": "^7.0.0", diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json new file mode 100644 index 00000000000..c176434c23b --- /dev/null +++ b/tsconfig.eslint.json @@ -0,0 +1,25 @@ +{ + // https://typescript-eslint.io/docs/linting/typed-linting/monorepos/#one-root-tsconfigjson + // extend your base config to share compilerOptions, etc + "extends": "./tsconfig.json", + "compilerOptions": { + // ensure that nobody can accidentally use this config for a build + "noEmit": true + }, + "include": [ + "examples/*/src/**/*.ts", + "examples/*/src/**/*.tsx", + "examples/monaco-graphql-nextjs/next-env.d.ts", + "examples/monaco-graphql-react-vite/vite.config.ts", + "packages/*/src/**/*.ts", + "packages/*/src/**/*.tsx", + "packages/*/vite.config.ts", + "packages/graphiql/cypress/**/*.ts", + "packages/graphiql/cypress.config.ts", + "packages/graphiql/__mocks__/codemirror.ts", + "packages/graphiql/__mocks__/@graphiql/react.tsx", + "packages/graphql-language-service/benchmark/index.ts", + "packages/graphiql-react/vite.config.d.ts", + "packages/cm6-graphql/__tests__/test.spec.ts" + ] +} diff --git a/yarn.lock b/yarn.lock index 4e5718065cc..3003f766a4f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4256,6 +4256,11 @@ resolved "https://registry.yarnpkg.com/@types/semver/-/semver-6.2.2.tgz#5c27df09ca39e3c9beb4fae6b95f4d71426df0a9" integrity sha512-RxAwYt4rGwK5GyoRwuP0jT6ZHAVTdz2EqgsHmX0PYNjGsko+OeT4WFXXTs/lM3teJUJodM+SNtAL5/pXIJ61IQ== +"@types/semver@^7.3.12": + version "7.3.13" + resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.13.tgz#da4bfd73f49bd541d28920ab0e2bf0ee80f71c91" + integrity sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw== + "@types/semver@^7.3.9": version "7.3.10" resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.10.tgz#5f19ee40cbeff87d916eedc8c2bfe2305d957f73" @@ -4423,29 +4428,30 @@ dependencies: "@types/node" "*" -"@typescript-eslint/eslint-plugin@^5.27.0": - version "5.27.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.27.0.tgz#23d82a4f21aaafd8f69dbab7e716323bb6695cc8" - integrity sha512-DDrIA7GXtmHXr1VCcx9HivA39eprYBIFxbQEHI6NyraRDxCGpxAFiYQAT/1Y0vh1C+o2vfBiy4IuPoXxtTZCAQ== +"@typescript-eslint/eslint-plugin@^5.54.1": + version "5.54.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.54.1.tgz#0c5091289ce28372e38ab8d28e861d2dbe1ab29e" + integrity sha512-a2RQAkosH3d3ZIV08s3DcL/mcGc2M/UC528VkPULFxR9VnVPT8pBu0IyBAJJmVsCmhVfwQX1v6q+QGnmSe1bew== dependencies: - "@typescript-eslint/scope-manager" "5.27.0" - "@typescript-eslint/type-utils" "5.27.0" - "@typescript-eslint/utils" "5.27.0" + "@typescript-eslint/scope-manager" "5.54.1" + "@typescript-eslint/type-utils" "5.54.1" + "@typescript-eslint/utils" "5.54.1" debug "^4.3.4" - functional-red-black-tree "^1.0.1" + grapheme-splitter "^1.0.4" ignore "^5.2.0" + natural-compare-lite "^1.4.0" regexpp "^3.2.0" semver "^7.3.7" tsutils "^3.21.0" -"@typescript-eslint/parser@^5.27.0": - version "5.27.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.27.0.tgz#62bb091ed5cf9c7e126e80021bb563dcf36b6b12" - integrity sha512-8oGjQF46c52l7fMiPPvX4It3u3V3JipssqDfHQ2hcR0AeR8Zge+OYyKUCm5b70X72N1qXt0qgHenwN6Gc2SXZA== +"@typescript-eslint/parser@^5.54.1": + version "5.54.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.54.1.tgz#05761d7f777ef1c37c971d3af6631715099b084c" + integrity sha512-8zaIXJp/nG9Ff9vQNh7TI+C3nA6q6iIsGJ4B4L6MhZ7mHnTMR4YP5vp2xydmFXIy8rpyIVbNAG44871LMt6ujg== dependencies: - "@typescript-eslint/scope-manager" "5.27.0" - "@typescript-eslint/types" "5.27.0" - "@typescript-eslint/typescript-estree" "5.27.0" + "@typescript-eslint/scope-manager" "5.54.1" + "@typescript-eslint/types" "5.54.1" + "@typescript-eslint/typescript-estree" "5.54.1" debug "^4.3.4" "@typescript-eslint/scope-manager@5.27.0": @@ -4456,12 +4462,21 @@ "@typescript-eslint/types" "5.27.0" "@typescript-eslint/visitor-keys" "5.27.0" -"@typescript-eslint/type-utils@5.27.0": - version "5.27.0" - resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.27.0.tgz#36fd95f6747412251d79c795b586ba766cf0974b" - integrity sha512-vpTvRRchaf628Hb/Xzfek+85o//zEUotr1SmexKvTfs7czXfYjXVT/a5yDbpzLBX1rhbqxjDdr1Gyo0x1Fc64g== +"@typescript-eslint/scope-manager@5.54.1": + version "5.54.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.54.1.tgz#6d864b4915741c608a58ce9912edf5a02bb58735" + integrity sha512-zWKuGliXxvuxyM71UA/EcPxaviw39dB2504LqAmFDjmkpO8qNLHcmzlh6pbHs1h/7YQ9bnsO8CCcYCSA8sykUg== + dependencies: + "@typescript-eslint/types" "5.54.1" + "@typescript-eslint/visitor-keys" "5.54.1" + +"@typescript-eslint/type-utils@5.54.1": + version "5.54.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.54.1.tgz#4825918ec27e55da8bb99cd07ec2a8e5f50ab748" + integrity sha512-WREHsTz0GqVYLIbzIZYbmUUr95DKEKIXZNH57W3s+4bVnuF1TKe2jH8ZNH8rO1CeMY3U4j4UQeqPNkHMiGem3g== dependencies: - "@typescript-eslint/utils" "5.27.0" + "@typescript-eslint/typescript-estree" "5.54.1" + "@typescript-eslint/utils" "5.54.1" debug "^4.3.4" tsutils "^3.21.0" @@ -4470,6 +4485,11 @@ resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.27.0.tgz#c3f44b9dda6177a9554f94a74745ca495ba9c001" integrity sha512-lY6C7oGm9a/GWhmUDOs3xAVRz4ty/XKlQ2fOLr8GAIryGn0+UBOoJDWyHer3UgrHkenorwvBnphhP+zPmzmw0A== +"@typescript-eslint/types@5.54.1": + version "5.54.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.54.1.tgz#29fbac29a716d0f08c62fe5de70c9b6735de215c" + integrity sha512-G9+1vVazrfAfbtmCapJX8jRo2E4MDXxgm/IMOF4oGh3kq7XuK3JRkOg6y2Qu1VsTRmWETyTkWt1wxy7X7/yLkw== + "@typescript-eslint/typescript-estree@5.27.0": version "5.27.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.27.0.tgz#7965f5b553c634c5354a47dcce0b40b94611e995" @@ -4483,7 +4503,34 @@ semver "^7.3.7" tsutils "^3.21.0" -"@typescript-eslint/utils@5.27.0", "@typescript-eslint/utils@^5.10.0": +"@typescript-eslint/typescript-estree@5.54.1": + version "5.54.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.54.1.tgz#df7b6ae05fd8fef724a87afa7e2f57fa4a599be1" + integrity sha512-bjK5t+S6ffHnVwA0qRPTZrxKSaFYocwFIkZx5k7pvWfsB1I57pO/0M0Skatzzw1sCkjJ83AfGTL0oFIFiDX3bg== + dependencies: + "@typescript-eslint/types" "5.54.1" + "@typescript-eslint/visitor-keys" "5.54.1" + debug "^4.3.4" + globby "^11.1.0" + is-glob "^4.0.3" + semver "^7.3.7" + tsutils "^3.21.0" + +"@typescript-eslint/utils@5.54.1": + version "5.54.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.54.1.tgz#7a3ee47409285387b9d4609ea7e1020d1797ec34" + integrity sha512-IY5dyQM8XD1zfDe5X8jegX6r2EVU5o/WJnLu/znLPWCBF7KNGC+adacXnt5jEYS9JixDcoccI6CvE4RCjHMzCQ== + dependencies: + "@types/json-schema" "^7.0.9" + "@types/semver" "^7.3.12" + "@typescript-eslint/scope-manager" "5.54.1" + "@typescript-eslint/types" "5.54.1" + "@typescript-eslint/typescript-estree" "5.54.1" + eslint-scope "^5.1.1" + eslint-utils "^3.0.0" + semver "^7.3.7" + +"@typescript-eslint/utils@^5.10.0": version "5.27.0" resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.27.0.tgz#d0021cbf686467a6a9499bd0589e19665f9f7e71" integrity sha512-nZvCrkIJppym7cIbP3pOwIkAefXOmfGPnCM0LQfzNaKxJHI6VjI8NC662uoiPlaf5f6ymkTy9C3NQXev2mdXmA== @@ -4503,6 +4550,14 @@ "@typescript-eslint/types" "5.27.0" eslint-visitor-keys "^3.3.0" +"@typescript-eslint/visitor-keys@5.54.1": + version "5.54.1" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.54.1.tgz#d7a8a0f7181d6ac748f4d47b2306e0513b98bf8b" + integrity sha512-q8iSoHTgwCfgcRJ2l2x+xCbu8nBlRAlsQ33k24Adj8eoVBE0f8dUeI+bAa8F84Mv05UGbAx57g2zrRsYIooqQg== + dependencies: + "@typescript-eslint/types" "5.54.1" + eslint-visitor-keys "^3.3.0" + "@ungap/promise-all-settled@1.1.2": version "1.1.2" resolved "https://registry.yarnpkg.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz#aa58042711d6e3275dd37dc597e5d31e8c290a44" @@ -9309,11 +9364,6 @@ function.prototype.name@^1.1.5: es-abstract "^1.19.0" functions-have-names "^1.2.2" -functional-red-black-tree@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327" - integrity sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc= - functions-have-names@^1.2.2: version "1.2.3" resolved "https://registry.yarnpkg.com/functions-have-names/-/functions-have-names-1.2.3.tgz#0404fe4ee2ba2f607f0e0ec3c80bae994133b834" @@ -12482,6 +12532,11 @@ napi-build-utils@^1.0.1: resolved "https://registry.yarnpkg.com/napi-build-utils/-/napi-build-utils-1.0.2.tgz#b1fddc0b2c46e380a0b7a76f984dd47c41a13806" integrity sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg== +natural-compare-lite@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/natural-compare-lite/-/natural-compare-lite-1.4.0.tgz#17b09581988979fddafe0201e931ba933c96cbb4" + integrity sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g== + natural-compare@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" From 8d50a641a4b9ce6b187b9d2b80c6581cc3ea18f8 Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Mon, 6 Mar 2023 20:43:10 +0100 Subject: [PATCH 02/13] fixes --- .eslintrc.js | 6 +++++- .../src/interface/getAutocompleteSuggestions.ts | 4 ++-- .../graphql-language-service/src/interface/getDefinition.ts | 2 +- .../src/interface/getDiagnostics.ts | 2 +- .../src/interface/getHoverInformation.ts | 2 +- .../src/utils/getVariablesJSONSchema.ts | 2 +- packages/monaco-graphql/src/graphqlMode.ts | 2 +- packages/monaco-graphql/src/languageFeatures.ts | 2 +- packages/vscode-graphql-execution/src/helpers/source.ts | 2 +- .../vscode-graphql-execution/src/providers/exec-content.ts | 6 +++--- 10 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index f8b20ac3cff..6928b5ca807 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -295,7 +295,11 @@ module.exports = { '@typescript-eslint/no-unnecessary-type-assertion': 'error', }, parserOptions: { - project: ['tsconfig.eslint.json'], + project: [ + 'packages/*/tsconfig.json', + 'examples/*/tsconfig.json', + 'packages/graphiql/cypress/tsconfig.json', + ], }, }, // Cypress plugin, global, etc., only for cypress directory diff --git a/packages/graphql-language-service/src/interface/getAutocompleteSuggestions.ts b/packages/graphql-language-service/src/interface/getAutocompleteSuggestions.ts index 03951cec076..6374097bd3c 100644 --- a/packages/graphql-language-service/src/interface/getAutocompleteSuggestions.ts +++ b/packages/graphql-language-service/src/interface/getAutocompleteSuggestions.ts @@ -644,7 +644,7 @@ function getSuggestionsForImplements( state.kind === RuleKinds.INTERFACE_DEF && !schemaInterfaceNames.includes(state.name) ) { - inlineInterfaces.add(state.name); + inlineInterfaces.add(state.name); } // gather the other interfaces the current type/interface definition implements // so we can filter them out below @@ -1047,7 +1047,7 @@ export function canUseDirective( state: State['prevState'], directive: GraphQLDirective, ): boolean { - if (!state || !state.kind) { + if (!state?.kind) { return false; } const { kind, prevState } = state; diff --git a/packages/graphql-language-service/src/interface/getDefinition.ts b/packages/graphql-language-service/src/interface/getDefinition.ts index b0156f9a88d..52747559c12 100644 --- a/packages/graphql-language-service/src/interface/getDefinition.ts +++ b/packages/graphql-language-service/src/interface/getDefinition.ts @@ -39,7 +39,7 @@ function assert(value: any, message: string) { function getRange(text: string, node: ASTNode): Range { const location = node.loc as Location; assert(location, 'Expected ASTNode to have a location.'); - return locToRange(text, location) as Range; + return locToRange(text, location) ; } function getPosition(text: string, node: ASTNode): Position { diff --git a/packages/graphql-language-service/src/interface/getDiagnostics.ts b/packages/graphql-language-service/src/interface/getDiagnostics.ts index 6b88cfd3785..396339d9787 100644 --- a/packages/graphql-language-service/src/interface/getDiagnostics.ts +++ b/packages/graphql-language-service/src/interface/getDiagnostics.ts @@ -87,7 +87,7 @@ export function getDiagnostics( return [ { - severity: DIAGNOSTIC_SEVERITY.Error as DiagnosticSeverity, + severity: DIAGNOSTIC_SEVERITY.Error , message: error.message, source: 'GraphQL: Syntax', range, diff --git a/packages/graphql-language-service/src/interface/getHoverInformation.ts b/packages/graphql-language-service/src/interface/getHoverInformation.ts index ef523c763cf..1d083bad40e 100644 --- a/packages/graphql-language-service/src/interface/getHoverInformation.ts +++ b/packages/graphql-language-service/src/interface/getHoverInformation.ts @@ -122,7 +122,7 @@ function renderQualifiedField( if (!typeInfo.fieldDef) { return; } - const fieldName = typeInfo.fieldDef.name as string; + const fieldName = typeInfo.fieldDef.name ; if (fieldName.slice(0, 2) !== '__') { renderType(into, typeInfo, options, typeInfo.parentType as GraphQLType); text(into, '.'); diff --git a/packages/graphql-language-service/src/utils/getVariablesJSONSchema.ts b/packages/graphql-language-service/src/utils/getVariablesJSONSchema.ts index 63bc2eebf39..5bc3a2db0ee 100644 --- a/packages/graphql-language-service/src/utils/getVariablesJSONSchema.ts +++ b/packages/graphql-language-service/src/utils/getVariablesJSONSchema.ts @@ -243,7 +243,7 @@ function getJSONSchemaFromGraphQLType( }); } }); - definitions![type.name] = fieldDef; + definitions[type.name] = fieldDef; } } // append descriptions diff --git a/packages/monaco-graphql/src/graphqlMode.ts b/packages/monaco-graphql/src/graphqlMode.ts index e89e9a16d12..51bb0742cd3 100644 --- a/packages/monaco-graphql/src/graphqlMode.ts +++ b/packages/monaco-graphql/src/graphqlMode.ts @@ -24,7 +24,7 @@ export function setupMode(defaults: MonacoGraphQLAPI): IDisposable { ...uris: Uri[] ): Promise => { try { - return client!.getLanguageServiceWorker(...uris); + return client.getLanguageServiceWorker(...uris); } catch { throw new Error('Error fetching graphql language service worker'); } diff --git a/packages/monaco-graphql/src/languageFeatures.ts b/packages/monaco-graphql/src/languageFeatures.ts index b8bb346a947..5f382c42889 100644 --- a/packages/monaco-graphql/src/languageFeatures.ts +++ b/packages/monaco-graphql/src/languageFeatures.ts @@ -208,7 +208,7 @@ export function toCompletion( range: entry.range, kind: toCompletionItemKind(entry.kind as lsCompletionItemKind), label: entry.label, - insertText: entry.insertText ?? (entry.label as string), + insertText: entry.insertText ?? (entry.label ), insertTextRules: entry.insertText ? monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet : undefined, diff --git a/packages/vscode-graphql-execution/src/helpers/source.ts b/packages/vscode-graphql-execution/src/helpers/source.ts index d2fc1c03bd2..f7999e397ef 100644 --- a/packages/vscode-graphql-execution/src/helpers/source.ts +++ b/packages/vscode-graphql-execution/src/helpers/source.ts @@ -47,7 +47,7 @@ export class SourceHelper { } if (namedTypeNode) { // TODO: Handle this for object types/ enums/ custom scalars - return (namedTypeNode as NamedTypeNode).name.value as GraphQLScalarType; + return (namedTypeNode as NamedTypeNode).name.value; } // TODO: Is handling all via string a correct fallback? return 'String'; diff --git a/packages/vscode-graphql-execution/src/providers/exec-content.ts b/packages/vscode-graphql-execution/src/providers/exec-content.ts index 42f3cf561a6..1287b56f7ee 100644 --- a/packages/vscode-graphql-execution/src/providers/exec-content.ts +++ b/packages/vscode-graphql-execution/src/providers/exec-content.ts @@ -146,7 +146,7 @@ export class GraphQLContentProvider implements TextDocumentContentProvider { if (schema && Array.isArray(schema)) { schema.map(s => { if (this.validUrlFromSchema(s as string)) { - endpoints!.default.url = s.toString(); + endpoints.default.url = s.toString(); } }); } else if (schema && this.validUrlFromSchema(schema as string)) { @@ -182,7 +182,7 @@ export class GraphQLContentProvider implements TextDocumentContentProvider { return; } const config = await loadConfig({ - rootDir: rootDir!.uri.fsPath, + rootDir: rootDir.uri.fsPath, legacy: true, }); const projectConfig = config?.getProjectForFile(this.literal.uri); @@ -246,7 +246,7 @@ export class GraphQLContentProvider implements TextDocumentContentProvider { this.reportError(`Error: this file is outside the workspace.`); return; } - const config = await loadConfig({ rootDir: rootDir!.uri.fsPath }); + const config = await loadConfig({ rootDir: rootDir.uri.fsPath }); const projectConfig = config?.getProjectForFile(literal.uri); if (!projectConfig!.schema) { From 270c7ded71e265cb28297d04940c48664c962110 Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Mon, 6 Mar 2023 20:46:49 +0100 Subject: [PATCH 03/13] prettier --- .../graphql-language-service/src/interface/getDefinition.ts | 2 +- .../graphql-language-service/src/interface/getDiagnostics.ts | 2 +- .../src/interface/getHoverInformation.ts | 2 +- packages/monaco-graphql/src/languageFeatures.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/graphql-language-service/src/interface/getDefinition.ts b/packages/graphql-language-service/src/interface/getDefinition.ts index 52747559c12..32d6a781585 100644 --- a/packages/graphql-language-service/src/interface/getDefinition.ts +++ b/packages/graphql-language-service/src/interface/getDefinition.ts @@ -39,7 +39,7 @@ function assert(value: any, message: string) { function getRange(text: string, node: ASTNode): Range { const location = node.loc as Location; assert(location, 'Expected ASTNode to have a location.'); - return locToRange(text, location) ; + return locToRange(text, location); } function getPosition(text: string, node: ASTNode): Position { diff --git a/packages/graphql-language-service/src/interface/getDiagnostics.ts b/packages/graphql-language-service/src/interface/getDiagnostics.ts index 396339d9787..046ebcb4197 100644 --- a/packages/graphql-language-service/src/interface/getDiagnostics.ts +++ b/packages/graphql-language-service/src/interface/getDiagnostics.ts @@ -87,7 +87,7 @@ export function getDiagnostics( return [ { - severity: DIAGNOSTIC_SEVERITY.Error , + severity: DIAGNOSTIC_SEVERITY.Error, message: error.message, source: 'GraphQL: Syntax', range, diff --git a/packages/graphql-language-service/src/interface/getHoverInformation.ts b/packages/graphql-language-service/src/interface/getHoverInformation.ts index 1d083bad40e..a7003b605f8 100644 --- a/packages/graphql-language-service/src/interface/getHoverInformation.ts +++ b/packages/graphql-language-service/src/interface/getHoverInformation.ts @@ -122,7 +122,7 @@ function renderQualifiedField( if (!typeInfo.fieldDef) { return; } - const fieldName = typeInfo.fieldDef.name ; + const fieldName = typeInfo.fieldDef.name; if (fieldName.slice(0, 2) !== '__') { renderType(into, typeInfo, options, typeInfo.parentType as GraphQLType); text(into, '.'); diff --git a/packages/monaco-graphql/src/languageFeatures.ts b/packages/monaco-graphql/src/languageFeatures.ts index 5f382c42889..2179b3c7470 100644 --- a/packages/monaco-graphql/src/languageFeatures.ts +++ b/packages/monaco-graphql/src/languageFeatures.ts @@ -208,7 +208,7 @@ export function toCompletion( range: entry.range, kind: toCompletionItemKind(entry.kind as lsCompletionItemKind), label: entry.label, - insertText: entry.insertText ?? (entry.label ), + insertText: entry.insertText ?? entry.label, insertTextRules: entry.insertText ? monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet : undefined, From be15966e53bc1dc161acb86dfc1dac2cb4054a19 Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Mon, 6 Mar 2023 21:01:28 +0100 Subject: [PATCH 04/13] fixes --- .../src/MessageProcessor.ts | 18 ++++++++---------- packages/monaco-graphql/src/LanguageService.ts | 2 +- tsconfig.eslint.json | 18 +++++------------- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/packages/graphql-language-service-server/src/MessageProcessor.ts b/packages/graphql-language-service-server/src/MessageProcessor.ts index 16400d75dfa..5fd0333a1bb 100644 --- a/packages/graphql-language-service-server/src/MessageProcessor.ts +++ b/packages/graphql-language-service-server/src/MessageProcessor.ts @@ -318,7 +318,7 @@ export class MessageProcessor { // We aren't able to use initialization event for this // and the config change event is after the fact. - if (!params || !params.textDocument) { + if (!params?.textDocument) { throw new Error('`textDocument` argument is required.'); } const { textDocument } = params; @@ -419,7 +419,7 @@ export class MessageProcessor { // e.g. auto-completions. if (!params?.textDocument?.uri || !params.contentChanges) { throw new Error( - '`textDocument`, `textDocument.uri`, and `contentChanges` arguments are required.', + '`textDocument.uri` and `contentChanges` arguments are required.', ); } const { textDocument, contentChanges } = params; @@ -501,7 +501,7 @@ export class MessageProcessor { // For every `textDocument/didClose` event, delete the cached entry. // This is to keep a low memory usage && switch the source of truth to // the file on disk. - if (!params || !params.textDocument) { + if (!params?.textDocument) { throw new Error('`textDocument` is required.'); } const { textDocument } = params; @@ -532,13 +532,11 @@ export class MessageProcessor { validateDocumentAndPosition(params: CompletionParams): void { if ( - !params || - !params.textDocument || - !params.textDocument.uri || + !params?.textDocument?.uri || !params.position ) { throw new Error( - '`textDocument`, `textDocument.uri`, and `position` arguments are required.', + '`textDocument.uri` and `position` arguments are required.', ); } } @@ -734,7 +732,7 @@ export class MessageProcessor { return []; } - if (!params || !params.textDocument || !params.position) { + if (!params?.textDocument || !params.position) { throw new Error('`textDocument` and `position` arguments are required.'); } const { textDocument, position } = params; @@ -831,7 +829,7 @@ export class MessageProcessor { return []; } - if (!params || !params.textDocument) { + if (!params?.textDocument) { throw new Error('`textDocument` argument is required.'); } @@ -852,7 +850,7 @@ export class MessageProcessor { // return []; // } - // if (!params || !params.textDocument) { + // if (!params?.textDocument) { // throw new Error('`textDocument` argument is required.'); // } diff --git a/packages/monaco-graphql/src/LanguageService.ts b/packages/monaco-graphql/src/LanguageService.ts index 1339d7c3ceb..bd3b2ccaea5 100644 --- a/packages/monaco-graphql/src/LanguageService.ts +++ b/packages/monaco-graphql/src/LanguageService.ts @@ -102,7 +102,7 @@ export class LanguageService { * @returns {SchemaCacheItem | undefined} */ public getSchemaForFile(uri: string): SchemaCacheItem | undefined { - if (!this._schemas || !this._schemas.length) { + if (!this._schemas?.length) { return; } if (this._schemas.length === 1) { diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index c176434c23b..b76f24cd0e9 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -7,19 +7,11 @@ "noEmit": true }, "include": [ - "examples/*/src/**/*.ts", - "examples/*/src/**/*.tsx", - "examples/monaco-graphql-nextjs/next-env.d.ts", - "examples/monaco-graphql-react-vite/vite.config.ts", - "packages/*/src/**/*.ts", - "packages/*/src/**/*.tsx", - "packages/*/vite.config.ts", - "packages/graphiql/cypress/**/*.ts", - "packages/graphiql/cypress.config.ts", - "packages/graphiql/__mocks__/codemirror.ts", - "packages/graphiql/__mocks__/@graphiql/react.tsx", + "packages/graphql-language-service/src/utils/__tests__/**/*.ts", + "packages/graphql-language-service/src/parser/__tests__/**/*.ts", + "packages/graphql-language-service/src/interface/__tests__/**/*.ts", "packages/graphql-language-service/benchmark/index.ts", - "packages/graphiql-react/vite.config.d.ts", - "packages/cm6-graphql/__tests__/test.spec.ts" + "packages/graphql-language-service-server/src/__tests__/**/*.ts", + "packages/graphql-language-service-cli/src/__tests__/**/*.ts" ] } From ecf1bc4399b2cf6807a3f02bb38b6eee0ddaf977 Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Mon, 6 Mar 2023 21:02:02 +0100 Subject: [PATCH 05/13] prettier --- .../graphql-language-service-server/src/MessageProcessor.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/graphql-language-service-server/src/MessageProcessor.ts b/packages/graphql-language-service-server/src/MessageProcessor.ts index 5fd0333a1bb..06808a1423c 100644 --- a/packages/graphql-language-service-server/src/MessageProcessor.ts +++ b/packages/graphql-language-service-server/src/MessageProcessor.ts @@ -531,10 +531,7 @@ export class MessageProcessor { } validateDocumentAndPosition(params: CompletionParams): void { - if ( - !params?.textDocument?.uri || - !params.position - ) { + if (!params?.textDocument?.uri || !params.position) { throw new Error( '`textDocument.uri` and `position` arguments are required.', ); From 39b34f80767896a8784a9d9f62549484b44e1cbf Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Mon, 6 Mar 2023 21:17:13 +0100 Subject: [PATCH 06/13] fixes --- .eslintrc.js | 1 + examples/monaco-graphql-webpack/src/editors.ts | 8 ++++---- examples/monaco-graphql-webpack/src/index.ts | 4 ++-- examples/monaco-graphql-webpack/src/schema.ts | 2 +- .../graphiql-toolkit/src/create-fetcher/lib.ts | 2 +- packages/graphiql-toolkit/src/storage/query.ts | 2 +- .../src/MessageProcessor.ts | 6 +++--- .../src/__tests__/GraphQLCache-test.ts | 4 ++-- tsconfig.eslint.json | 18 +++++++++++++++++- 9 files changed, 32 insertions(+), 15 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 6928b5ca807..d097cf3404a 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -299,6 +299,7 @@ module.exports = { 'packages/*/tsconfig.json', 'examples/*/tsconfig.json', 'packages/graphiql/cypress/tsconfig.json', + 'tsconfig.eslint.json' ], }, }, diff --git a/examples/monaco-graphql-webpack/src/editors.ts b/examples/monaco-graphql-webpack/src/editors.ts index 1c56e7436dd..2e70359b512 100644 --- a/examples/monaco-graphql-webpack/src/editors.ts +++ b/examples/monaco-graphql-webpack/src/editors.ts @@ -42,7 +42,7 @@ export function createEditors() { ); const variablesEditor = monaco.editor.create( - document.getElementById('variables') as HTMLElement, + document.getElementById('variables'), { model: variablesModel, language: 'json', @@ -63,7 +63,7 @@ export function createEditors() { ); const operationEditor = monaco.editor.create( - document.getElementById('operation') as HTMLElement, + document.getElementById('operation'), { model: operationModel, formatOnPaste: true, @@ -81,7 +81,7 @@ export function createEditors() { ); const schemaEditor = monaco.editor.create( - document.getElementById('schema-sdl') as HTMLElement, + document.getElementById('schema-sdl'), { model: schemaModel, formatOnPaste: true, @@ -99,7 +99,7 @@ export function createEditors() { ); const resultsEditor = monaco.editor.create( - document.getElementById('results') as HTMLElement, + document.getElementById('results'), { model: resultsModel, language: 'json', diff --git a/examples/monaco-graphql-webpack/src/index.ts b/examples/monaco-graphql-webpack/src/index.ts index 1ce00ce3025..cb992452936 100644 --- a/examples/monaco-graphql-webpack/src/index.ts +++ b/examples/monaco-graphql-webpack/src/index.ts @@ -153,13 +153,13 @@ async function render() { const body: { variables?: string; query: string } = { query: operation, }; - // parse the variables with JSONC so we can have comments! + // parse the variables with JSONC, so we can have comments! const parsedVariables = JSONC.parse(variables); if (parsedVariables && Object.keys(parsedVariables).length) { body.variables = JSON.stringify(parsedVariables, null, 2); } const result = await fetch( - schemaFetcher.currentSchema.value as string, + schemaFetcher.currentSchema.value, { method: 'POST', headers: { diff --git a/examples/monaco-graphql-webpack/src/schema.ts b/examples/monaco-graphql-webpack/src/schema.ts index f250aabb3ae..d6da1314c30 100644 --- a/examples/monaco-graphql-webpack/src/schema.ts +++ b/examples/monaco-graphql-webpack/src/schema.ts @@ -75,7 +75,7 @@ class MySchemaFetcher { async loadSchema() { try { setSchemaStatus('Schema Loading...'); - const url = this._currentSchema.value as string; + const url = this._currentSchema.value; const headers = { 'content-type': 'application/json', diff --git a/packages/graphiql-toolkit/src/create-fetcher/lib.ts b/packages/graphiql-toolkit/src/create-fetcher/lib.ts index ff1550f943c..58ea28c00c5 100644 --- a/packages/graphiql-toolkit/src/create-fetcher/lib.ts +++ b/packages/graphiql-toolkit/src/create-fetcher/lib.ts @@ -104,7 +104,7 @@ export const createWebsocketsFetcherFromUrl = ( export const createWebsocketsFetcherFromClient = (wsClient: Client) => (graphQLParams: FetcherParams) => makeAsyncIterableIteratorFromSink(sink => - wsClient!.subscribe(graphQLParams, { + wsClient.subscribe(graphQLParams, { ...sink, error: err => { if (err instanceof CloseEvent) { diff --git a/packages/graphiql-toolkit/src/storage/query.ts b/packages/graphiql-toolkit/src/storage/query.ts index 86040e1621a..25a3b42607f 100644 --- a/packages/graphiql-toolkit/src/storage/query.ts +++ b/packages/graphiql-toolkit/src/storage/query.ts @@ -86,7 +86,7 @@ export class QueryStore { this.key, JSON.stringify({ [this.key]: items }), ); - if (!response || !response.error) { + if (!response?.error) { this.items = items; } else if (response.isQuotaError && this.maxSize) { // Only try to delete last items on LRU stores diff --git a/packages/graphql-language-service-server/src/MessageProcessor.ts b/packages/graphql-language-service-server/src/MessageProcessor.ts index 06808a1423c..0f4978a6ef0 100644 --- a/packages/graphql-language-service-server/src/MessageProcessor.ts +++ b/packages/graphql-language-service-server/src/MessageProcessor.ts @@ -832,7 +832,7 @@ export class MessageProcessor { const { textDocument } = params; const cachedDocument = this._getCachedDocument(textDocument.uri); - if (!cachedDocument || !cachedDocument.contents[0]) { + if (!cachedDocument?.contents[0]) { return []; } @@ -1098,9 +1098,9 @@ export class MessageProcessor { // build full system URI path with protocol const uri = URI.file(filePath).toString(); - // i would use the already existing graphql-config AST, but there are a few reasons we can't yet + // I would use the already existing graphql-config AST, but there are a few reasons we can't yet const contents = this._parser(document.rawSDL, uri); - if (!contents[0] || !contents[0].query) { + if (!contents[0]?.query) { return; } await this._updateObjectTypeDefinition(uri, contents); diff --git a/packages/graphql-language-service-server/src/__tests__/GraphQLCache-test.ts b/packages/graphql-language-service-server/src/__tests__/GraphQLCache-test.ts index 5d8a6580ed1..a774d7f771f 100644 --- a/packages/graphql-language-service-server/src/__tests__/GraphQLCache-test.ts +++ b/packages/graphql-language-service-server/src/__tests__/GraphQLCache-test.ts @@ -118,7 +118,7 @@ describe('GraphQLCache', () => { it('extend the schema with appropriate custom directive', async () => { const schema = (await cache.getSchema( 'testWithCustomDirectives', - )) as GraphQLSchema; + )); expect(withoutASTNode(schema.getDirective('customDirective'))).toEqual( // objectContaining is used to pass this test without changing the code if more properties are added in GraphQLDirective class in the new version of graphql module. expect.objectContaining({ @@ -132,7 +132,7 @@ describe('GraphQLCache', () => { }); it('extend the schema with appropriate custom directive 2', async () => { - const schema = (await cache.getSchema('testWithSchema')) as GraphQLSchema; + const schema = (await cache.getSchema('testWithSchema')); expect(withoutASTNode(schema.getDirective('customDirective'))).toEqual( // objectContaining is used to pass this test without changing the code if more properties are added in GraphQLDirective class in the new version of graphql module. expect.objectContaining({ diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index b76f24cd0e9..53a084b326a 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -12,6 +12,22 @@ "packages/graphql-language-service/src/interface/__tests__/**/*.ts", "packages/graphql-language-service/benchmark/index.ts", "packages/graphql-language-service-server/src/__tests__/**/*.ts", - "packages/graphql-language-service-cli/src/__tests__/**/*.ts" + "packages/graphql-language-service-cli/src/__tests__/**/*.ts", + "packages/graphiql/src/components/__tests__/**/*.ts", + "packages/graphiql/src/components/__tests__/**/*.tsx", + "packages/graphiql/cypress.config.ts", + "packages/graphiql/__mocks__/codemirror.ts", + "packages/graphiql/__mocks__/@graphiql/react.tsx", + "packages/graphiql-toolkit/src/storage/__tests__/**/*.ts", + "packages/graphiql-toolkit/src/graphql-helpers/__tests__/**/*.ts", + "packages/graphiql-toolkit/src/create-fetcher/__tests__/**/*.ts", + "packages/*/vite.config.ts", + "examples/*/vite.config.ts", + "packages/graphiql-react/vite.config.d.ts", + "packages/codemirror-graphql/src/variables/__tests__/**/*.ts", + "packages/codemirror-graphql/src/utils/__tests__/**/*.ts", + "packages/codemirror-graphql/src/results/__tests__/**/*.ts", + "packages/codemirror-graphql/src/__tests__/**/*.ts", + "packages/cm6-graphql/__tests__/**/*.ts" ] } From b2bee513d3cd1a72595d52179b5d3f4281e33169 Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Mon, 6 Mar 2023 21:17:49 +0100 Subject: [PATCH 07/13] prettier --- .eslintrc.js | 2 +- examples/monaco-graphql-webpack/src/index.ts | 17 +++++++---------- .../src/__tests__/GraphQLCache-test.ts | 6 ++---- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index d097cf3404a..e994e39d3d8 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -299,7 +299,7 @@ module.exports = { 'packages/*/tsconfig.json', 'examples/*/tsconfig.json', 'packages/graphiql/cypress/tsconfig.json', - 'tsconfig.eslint.json' + 'tsconfig.eslint.json', ], }, }, diff --git a/examples/monaco-graphql-webpack/src/index.ts b/examples/monaco-graphql-webpack/src/index.ts index cb992452936..2f35ea8a3e2 100644 --- a/examples/monaco-graphql-webpack/src/index.ts +++ b/examples/monaco-graphql-webpack/src/index.ts @@ -158,17 +158,14 @@ async function render() { if (parsedVariables && Object.keys(parsedVariables).length) { body.variables = JSON.stringify(parsedVariables, null, 2); } - const result = await fetch( - schemaFetcher.currentSchema.value, - { - method: 'POST', - headers: { - 'content-type': 'application/json', - ...schemaFetcher.currentSchema?.headers, - }, - body: JSON.stringify(body, null, 2), + const result = await fetch(schemaFetcher.currentSchema.value, { + method: 'POST', + headers: { + 'content-type': 'application/json', + ...schemaFetcher.currentSchema?.headers, }, - ); + body: JSON.stringify(body, null, 2), + }); const resultText = await result.text(); resultsEditor.setValue(JSON.stringify(JSON.parse(resultText), null, 2)); diff --git a/packages/graphql-language-service-server/src/__tests__/GraphQLCache-test.ts b/packages/graphql-language-service-server/src/__tests__/GraphQLCache-test.ts index a774d7f771f..366463e5600 100644 --- a/packages/graphql-language-service-server/src/__tests__/GraphQLCache-test.ts +++ b/packages/graphql-language-service-server/src/__tests__/GraphQLCache-test.ts @@ -116,9 +116,7 @@ describe('GraphQLCache', () => { }); it('extend the schema with appropriate custom directive', async () => { - const schema = (await cache.getSchema( - 'testWithCustomDirectives', - )); + const schema = await cache.getSchema('testWithCustomDirectives'); expect(withoutASTNode(schema.getDirective('customDirective'))).toEqual( // objectContaining is used to pass this test without changing the code if more properties are added in GraphQLDirective class in the new version of graphql module. expect.objectContaining({ @@ -132,7 +130,7 @@ describe('GraphQLCache', () => { }); it('extend the schema with appropriate custom directive 2', async () => { - const schema = (await cache.getSchema('testWithSchema')); + const schema = await cache.getSchema('testWithSchema'); expect(withoutASTNode(schema.getDirective('customDirective'))).toEqual( // objectContaining is used to pass this test without changing the code if more properties are added in GraphQLDirective class in the new version of graphql module. expect.objectContaining({ From 85c863e421941873ea27fe0b44891c766fcfe4eb Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Mon, 6 Mar 2023 21:22:37 +0100 Subject: [PATCH 08/13] fixes --- .../components/__tests__/GraphiQL.spec.tsx | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/graphiql/src/components/__tests__/GraphiQL.spec.tsx b/packages/graphiql/src/components/__tests__/GraphiQL.spec.tsx index 06e6a9655f0..c8a90b7823b 100644 --- a/packages/graphiql/src/components/__tests__/GraphiQL.spec.tsx +++ b/packages/graphiql/src/components/__tests__/GraphiQL.spec.tsx @@ -165,9 +165,9 @@ describe('GraphiQL', () => { const { container } = render(); await waitFor(() => { - const mockEditor = container.querySelector( + const mockEditor = container.querySelector( '[data-testid="query-editor"] .mockCodeMirror', - ) as HTMLTextAreaElement; + ) ; expect(mockEditor.value).toContain('# Welcome to GraphiQL'); }); }); @@ -226,7 +226,7 @@ describe('GraphiQL', () => { const secondaryEditorTitle = container.querySelector( '.graphiql-editor-tools', - ) as Element; + ) ; // drag the editor tools handle up act(() => { @@ -300,8 +300,8 @@ describe('GraphiQL', () => { const dragBar = container.querySelector( '.graphiql-horizontal-drag-bar', - ) as Element; - const editors = container.querySelector('.graphiql-editors') as Element; + ) ; + const editors = container.querySelector('.graphiql-editors') ; act(() => { fireEvent.mouseDown(dragBar, { @@ -319,7 +319,7 @@ describe('GraphiQL', () => { await waitFor(() => { // 700 / (900 - 700) = 3.5 - expect((editors.parentElement as HTMLElement).style.flex).toEqual( + expect((editors.parentElement ).style.flex).toEqual( '3.5', ); }); @@ -345,7 +345,7 @@ describe('GraphiQL', () => { fireEvent.click( container.querySelector( '[aria-label="Show Documentation Explorer"]', - ) as Element, + ) , ); }); @@ -370,7 +370,7 @@ describe('GraphiQL', () => { expect( ( container.querySelector('.graphiql-plugin') - ?.parentElement as HTMLElement + ?.parentElement ).style.flex, ).toBe('1.977667493796526'); }); @@ -444,7 +444,7 @@ describe('GraphiQL', () => { act(() => { fireEvent.click( - container.querySelector('.graphiql-tab-add') as Element, + container.querySelector('.graphiql-tab-add') , ); }); @@ -456,7 +456,7 @@ describe('GraphiQL', () => { act(() => { fireEvent.click( - container.querySelector('.graphiql-tab-add') as Element, + container.querySelector('.graphiql-tab-add') , ); }); @@ -478,7 +478,7 @@ describe('GraphiQL', () => { act(() => { fireEvent.click( - container.querySelector('.graphiql-tab-add') as Element, + container.querySelector('.graphiql-tab-add') , ); }); @@ -490,7 +490,7 @@ describe('GraphiQL', () => { act(() => { fireEvent.click( - container.querySelector('.graphiql-tab-add') as Element, + container.querySelector('.graphiql-tab-add') , ); }); @@ -506,7 +506,7 @@ describe('GraphiQL', () => { act(() => { fireEvent.click( - container.querySelector('.graphiql-tab-add') as Element, + container.querySelector('.graphiql-tab-add') , ); }); @@ -520,7 +520,7 @@ describe('GraphiQL', () => { fireEvent.click( container.querySelector( '.graphiql-tab .graphiql-tab-close', - ) as Element, + ) , ); }); @@ -914,7 +914,7 @@ describe('GraphiQL', () => { fireEvent.change( container.querySelector( '[data-testid="query-editor"] .mockCodeMirror', - ) as Element, + ) , { target: { value: mockQuery2 }, }, @@ -963,7 +963,7 @@ describe('GraphiQL', () => { fireEvent.change( container.querySelector( '[aria-label="Variables"] .mockCodeMirror', - ) as Element, + ) , { target: { value: mockVariables2 }, }, @@ -1017,7 +1017,7 @@ describe('GraphiQL', () => { fireEvent.change( container.querySelector( '[aria-label="Headers"] .mockCodeMirror', - ) as Element, + ) , { target: { value: mockHeaders2 }, }, From 1be32f7911ed36a4204d1ae26a350b603b4e9e11 Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Mon, 6 Mar 2023 21:23:31 +0100 Subject: [PATCH 09/13] prettier --- .../components/__tests__/GraphiQL.spec.tsx | 58 ++++++------------- 1 file changed, 17 insertions(+), 41 deletions(-) diff --git a/packages/graphiql/src/components/__tests__/GraphiQL.spec.tsx b/packages/graphiql/src/components/__tests__/GraphiQL.spec.tsx index c8a90b7823b..9a813b512d2 100644 --- a/packages/graphiql/src/components/__tests__/GraphiQL.spec.tsx +++ b/packages/graphiql/src/components/__tests__/GraphiQL.spec.tsx @@ -167,7 +167,7 @@ describe('GraphiQL', () => { await waitFor(() => { const mockEditor = container.querySelector( '[data-testid="query-editor"] .mockCodeMirror', - ) ; + ); expect(mockEditor.value).toContain('# Welcome to GraphiQL'); }); }); @@ -226,7 +226,7 @@ describe('GraphiQL', () => { const secondaryEditorTitle = container.querySelector( '.graphiql-editor-tools', - ) ; + ); // drag the editor tools handle up act(() => { @@ -298,10 +298,8 @@ describe('GraphiQL', () => { const { container } = render(); - const dragBar = container.querySelector( - '.graphiql-horizontal-drag-bar', - ) ; - const editors = container.querySelector('.graphiql-editors') ; + const dragBar = container.querySelector('.graphiql-horizontal-drag-bar'); + const editors = container.querySelector('.graphiql-editors'); act(() => { fireEvent.mouseDown(dragBar, { @@ -319,9 +317,7 @@ describe('GraphiQL', () => { await waitFor(() => { // 700 / (900 - 700) = 3.5 - expect((editors.parentElement ).style.flex).toEqual( - '3.5', - ); + expect(editors.parentElement.style.flex).toEqual('3.5'); }); clientWidthSpy.mockRestore(); @@ -343,9 +339,7 @@ describe('GraphiQL', () => { act(() => { fireEvent.click( - container.querySelector( - '[aria-label="Show Documentation Explorer"]', - ) , + container.querySelector('[aria-label="Show Documentation Explorer"]'), ); }); @@ -368,10 +362,8 @@ describe('GraphiQL', () => { await waitFor(() => { // 797 / (1200 - 797) = 1.977667493796526 expect( - ( - container.querySelector('.graphiql-plugin') - ?.parentElement - ).style.flex, + (container.querySelector('.graphiql-plugin')?.parentElement).style + .flex, ).toBe('1.977667493796526'); }); @@ -443,9 +435,7 @@ describe('GraphiQL', () => { }); act(() => { - fireEvent.click( - container.querySelector('.graphiql-tab-add') , - ); + fireEvent.click(container.querySelector('.graphiql-tab-add')); }); await waitFor(() => { @@ -455,9 +445,7 @@ describe('GraphiQL', () => { }); act(() => { - fireEvent.click( - container.querySelector('.graphiql-tab-add') , - ); + fireEvent.click(container.querySelector('.graphiql-tab-add')); }); await waitFor(() => { @@ -477,9 +465,7 @@ describe('GraphiQL', () => { }); act(() => { - fireEvent.click( - container.querySelector('.graphiql-tab-add') , - ); + fireEvent.click(container.querySelector('.graphiql-tab-add')); }); await waitFor(() => { @@ -489,9 +475,7 @@ describe('GraphiQL', () => { }); act(() => { - fireEvent.click( - container.querySelector('.graphiql-tab-add') , - ); + fireEvent.click(container.querySelector('.graphiql-tab-add')); }); await waitFor(() => { @@ -505,9 +489,7 @@ describe('GraphiQL', () => { const { container } = render(); act(() => { - fireEvent.click( - container.querySelector('.graphiql-tab-add') , - ); + fireEvent.click(container.querySelector('.graphiql-tab-add')); }); await waitFor(() => { @@ -518,9 +500,7 @@ describe('GraphiQL', () => { act(() => { fireEvent.click( - container.querySelector( - '.graphiql-tab .graphiql-tab-close', - ) , + container.querySelector('.graphiql-tab .graphiql-tab-close'), ); }); @@ -914,7 +894,7 @@ describe('GraphiQL', () => { fireEvent.change( container.querySelector( '[data-testid="query-editor"] .mockCodeMirror', - ) , + ), { target: { value: mockQuery2 }, }, @@ -961,9 +941,7 @@ describe('GraphiQL', () => { act(() => { fireEvent.change( - container.querySelector( - '[aria-label="Variables"] .mockCodeMirror', - ) , + container.querySelector('[aria-label="Variables"] .mockCodeMirror'), { target: { value: mockVariables2 }, }, @@ -1015,9 +993,7 @@ describe('GraphiQL', () => { act(() => { fireEvent.change( - container.querySelector( - '[aria-label="Headers"] .mockCodeMirror', - ) , + container.querySelector('[aria-label="Headers"] .mockCodeMirror'), { target: { value: mockHeaders2 }, }, From 2dbb3f163d83df00a4b82a95885395b2752ca973 Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Mon, 6 Mar 2023 21:27:48 +0100 Subject: [PATCH 10/13] fixes --- .../src/components/__tests__/GraphiQL.spec.tsx | 3 +-- tsconfig.eslint.json | 12 +++--------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/packages/graphiql/src/components/__tests__/GraphiQL.spec.tsx b/packages/graphiql/src/components/__tests__/GraphiQL.spec.tsx index 9a813b512d2..889056bdf76 100644 --- a/packages/graphiql/src/components/__tests__/GraphiQL.spec.tsx +++ b/packages/graphiql/src/components/__tests__/GraphiQL.spec.tsx @@ -362,8 +362,7 @@ describe('GraphiQL', () => { await waitFor(() => { // 797 / (1200 - 797) = 1.977667493796526 expect( - (container.querySelector('.graphiql-plugin')?.parentElement).style - .flex, + container.querySelector('.graphiql-plugin')?.parentElement.style.flex, ).toBe('1.977667493796526'); }); diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index 53a084b326a..2a16b6247a7 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -7,9 +7,9 @@ "noEmit": true }, "include": [ - "packages/graphql-language-service/src/utils/__tests__/**/*.ts", - "packages/graphql-language-service/src/parser/__tests__/**/*.ts", - "packages/graphql-language-service/src/interface/__tests__/**/*.ts", + "packages/graphql-language-service/src/*/__tests__/**/*.ts", + "packages/graphiql-toolkit/src/*/__tests__/**/*.ts", + "packages/codemirror-graphql/src/*/__tests__/**/*.ts", "packages/graphql-language-service/benchmark/index.ts", "packages/graphql-language-service-server/src/__tests__/**/*.ts", "packages/graphql-language-service-cli/src/__tests__/**/*.ts", @@ -18,15 +18,9 @@ "packages/graphiql/cypress.config.ts", "packages/graphiql/__mocks__/codemirror.ts", "packages/graphiql/__mocks__/@graphiql/react.tsx", - "packages/graphiql-toolkit/src/storage/__tests__/**/*.ts", - "packages/graphiql-toolkit/src/graphql-helpers/__tests__/**/*.ts", - "packages/graphiql-toolkit/src/create-fetcher/__tests__/**/*.ts", "packages/*/vite.config.ts", "examples/*/vite.config.ts", "packages/graphiql-react/vite.config.d.ts", - "packages/codemirror-graphql/src/variables/__tests__/**/*.ts", - "packages/codemirror-graphql/src/utils/__tests__/**/*.ts", - "packages/codemirror-graphql/src/results/__tests__/**/*.ts", "packages/codemirror-graphql/src/__tests__/**/*.ts", "packages/cm6-graphql/__tests__/**/*.ts" ] From 8ab9e3a4bff2776f22f7cd60151a9017dbae99fc Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Mon, 6 Mar 2023 21:30:41 +0100 Subject: [PATCH 11/13] fixes --- tsconfig.eslint.json | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index 2a16b6247a7..d081e55aad2 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -7,21 +7,17 @@ "noEmit": true }, "include": [ - "packages/graphql-language-service/src/*/__tests__/**/*.ts", - "packages/graphiql-toolkit/src/*/__tests__/**/*.ts", - "packages/codemirror-graphql/src/*/__tests__/**/*.ts", - "packages/graphql-language-service/benchmark/index.ts", - "packages/graphql-language-service-server/src/__tests__/**/*.ts", - "packages/graphql-language-service-cli/src/__tests__/**/*.ts", + "packages/*/src/*/__tests__/**/*.ts", + "packages/*/src/__tests__/**/*.ts", + "packages/*/vite.config.ts", + "examples/*/vite.config.ts", "packages/graphiql/src/components/__tests__/**/*.ts", "packages/graphiql/src/components/__tests__/**/*.tsx", + "packages/cm6-graphql/__tests__/**/*.ts", + "packages/graphql-language-service/benchmark/index.ts", "packages/graphiql/cypress.config.ts", "packages/graphiql/__mocks__/codemirror.ts", "packages/graphiql/__mocks__/@graphiql/react.tsx", - "packages/*/vite.config.ts", - "examples/*/vite.config.ts", - "packages/graphiql-react/vite.config.d.ts", - "packages/codemirror-graphql/src/__tests__/**/*.ts", - "packages/cm6-graphql/__tests__/**/*.ts" + "packages/graphiql-react/vite.config.d.ts" ] } From 81bce30326aae38176d8f3f9867951eed96b8353 Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Mon, 6 Mar 2023 21:56:33 +0100 Subject: [PATCH 12/13] set `NODE_OPTIONS=--max-old-space-size=3500` --- .github/workflows/pr-check.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 4352a19cc01..2445c05f8a2 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -26,7 +26,8 @@ jobs: run: yarn build - name: ESLint - run: yarn lint + # fixes error on CI - Allocation failed - JavaScript heap out of memory + run: NODE_OPTIONS=--max-old-space-size=3500 yarn lint - name: Prettier Check run: yarn pretty-check From 62af6961d427b7e96d85df8223a7459cd388390f Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Mon, 6 Mar 2023 22:01:50 +0100 Subject: [PATCH 13/13] set `NODE_OPTIONS=--max-old-space-size=4096` --- .github/workflows/pr-check.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 2445c05f8a2..cf3bba65056 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -26,8 +26,8 @@ jobs: run: yarn build - name: ESLint - # fixes error on CI - Allocation failed - JavaScript heap out of memory - run: NODE_OPTIONS=--max-old-space-size=3500 yarn lint + # Fixes error on CI: Allocation failed - JavaScript heap out of memory + run: NODE_OPTIONS=--max-old-space-size=4096 yarn lint - name: Prettier Check run: yarn pretty-check