From 539dbdf9c2465fbbd0fa678ea60f381d2d123ddb Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Sat, 1 Apr 2023 00:31:22 +0200 Subject: [PATCH] fix --- .eslintrc.js | 1 + .../src/parser/__tests__/OnlineParserUtils.ts | 5 ++--- .../src/utils/getVariablesJSONSchema.ts | 8 +++++--- .../src/providers/exec-content.ts | 10 ++++++++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 22f1d3fdd68..e9d01166467 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -228,6 +228,7 @@ module.exports = { 'sort-imports': 0, 'symbol-description': 1, + 'sonarjs/no-ignored-return': 'error', 'unicorn/no-array-push-push': 'error', 'import/no-extraneous-dependencies': 'error', 'import/no-duplicates': 'error', diff --git a/packages/graphql-language-service/src/parser/__tests__/OnlineParserUtils.ts b/packages/graphql-language-service/src/parser/__tests__/OnlineParserUtils.ts index 3f5d6e7fe80..7a0c1d91ee2 100644 --- a/packages/graphql-language-service/src/parser/__tests__/OnlineParserUtils.ts +++ b/packages/graphql-language-service/src/parser/__tests__/OnlineParserUtils.ts @@ -127,13 +127,12 @@ export const getUtils = (source: string) => { }; export const performForEachType = (source, test) => { - Object.keys(typesMap).map(type => { - const { value, kind, valueType } = typesMap[type]; + for (const [type, { value, kind, valueType }] of Object.entries(typesMap)) { const utils = getUtils( source.replaceAll('__VALUE__', value).replaceAll('__TYPE__', type), ); test(utils, { type, value, kind, valueType }); - }); + } }; export const expectVarsDef = ( diff --git a/packages/graphql-language-service/src/utils/getVariablesJSONSchema.ts b/packages/graphql-language-service/src/utils/getVariablesJSONSchema.ts index 5bc3a2db0ee..7f32efce364 100644 --- a/packages/graphql-language-service/src/utils/getVariablesJSONSchema.ts +++ b/packages/graphql-language-service/src/utils/getVariablesJSONSchema.ts @@ -111,6 +111,7 @@ const scalarTypesMap: { [key: string]: JSONSchema6TypeName } = { class Marker { private set = new Set(); + mark(name: string): boolean { if (this.set.has(name)) { return false; @@ -238,9 +239,9 @@ function getJSONSchemaFromGraphQLType( fieldDef.required!.push(fieldName); } if (typeDefinitions) { - Object.keys(typeDefinitions).map(defName => { - definitions[defName] = typeDefinitions[defName]; - }); + for (const [defName, value] of Object.entries(typeDefinitions)) { + definitions[defName] = value; + } } }); definitions[type.name] = fieldDef; @@ -269,6 +270,7 @@ function getJSONSchemaFromGraphQLType( return { required, definition, definitions }; } + /** * Generates a JSONSchema6 valid document for operation(s) from a map of Map. * diff --git a/packages/vscode-graphql-execution/src/providers/exec-content.ts b/packages/vscode-graphql-execution/src/providers/exec-content.ts index 1287b56f7ee..cdece598f11 100644 --- a/packages/vscode-graphql-execution/src/providers/exec-content.ts +++ b/packages/vscode-graphql-execution/src/providers/exec-content.ts @@ -114,18 +114,22 @@ export class GraphQLContentProvider implements TextDocumentContentProvider { this.html = err.toString(); }); } + validUrlFromSchema(pathOrUrl: string) { return /^https?:\/\//.test(pathOrUrl); } + reportError(message: string) { this.outputChannel.appendLine(message); this.setContentAndUpdate(message); } + setContentAndUpdate(html: string) { this.html = html; this.update(this.uri); this.updatePanel(); } + async loadEndpoint( projectConfig?: GraphQLProjectConfig, ): Promise { @@ -144,11 +148,11 @@ export class GraphQLContentProvider implements TextDocumentContentProvider { ); const { schema } = projectConfig; if (schema && Array.isArray(schema)) { - schema.map(s => { + for (const s of schema) { if (this.validUrlFromSchema(s as string)) { endpoints.default.url = s.toString(); } - }); + } } else if (schema && this.validUrlFromSchema(schema as string)) { endpoints.default.url = schema.toString(); } @@ -174,6 +178,7 @@ export class GraphQLContentProvider implements TextDocumentContentProvider { const endpointName = await this.getEndpointName(endpointNames); return endpoints[endpointName] || endpoints.default; } + async loadProvider() { try { const rootDir = workspace.getWorkspaceFolder(Uri.file(this.literal.uri)); @@ -240,6 +245,7 @@ export class GraphQLContentProvider implements TextDocumentContentProvider { return; } } + async loadConfig() { const { rootDir, literal } = this; if (!rootDir) {