From c44ea4f1917b97daac815c08299b934c8ca57ed9 Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Fri, 2 Dec 2022 02:45:49 +0100 Subject: [PATCH] remove `mapCat()` in favor of `Array#flatMap()` --- .changeset/plenty-candles-shave.md | 5 ++++ .../src/interface/getDiagnostics.ts | 25 ++++++++----------- 2 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 .changeset/plenty-candles-shave.md diff --git a/.changeset/plenty-candles-shave.md b/.changeset/plenty-candles-shave.md new file mode 100644 index 00000000000..398e6983df4 --- /dev/null +++ b/.changeset/plenty-candles-shave.md @@ -0,0 +1,5 @@ +--- +'graphql-language-service': patch +--- + +remove `mapCat()` in favor of `Array#flatMap()` diff --git a/packages/graphql-language-service/src/interface/getDiagnostics.ts b/packages/graphql-language-service/src/interface/getDiagnostics.ts index 907faae6ccc..c7d9742ae61 100644 --- a/packages/graphql-language-service/src/interface/getDiagnostics.ts +++ b/packages/graphql-language-service/src/interface/getDiagnostics.ts @@ -113,27 +113,24 @@ export function validateQuery( return []; } - const validationErrorAnnotations = mapCat( - validateWithCustomRules(schema, ast, customRules, isRelayCompatMode), - error => annotations(error, DIAGNOSTIC_SEVERITY.Error, 'Validation'), + const validationErrorAnnotations = validateWithCustomRules( + schema, + ast, + customRules, + isRelayCompatMode, + ).flatMap(error => + annotations(error, DIAGNOSTIC_SEVERITY.Error, 'Validation'), ); // TODO: detect if > graphql@15.2.0, and use the new rule for this. - const deprecationWarningAnnotations = mapCat( - validate(schema, ast, [NoDeprecatedCustomRule]), - error => annotations(error, DIAGNOSTIC_SEVERITY.Warning, 'Deprecation'), + const deprecationWarningAnnotations = validate(schema, ast, [ + NoDeprecatedCustomRule, + ]).flatMap(error => + annotations(error, DIAGNOSTIC_SEVERITY.Warning, 'Deprecation'), ); return validationErrorAnnotations.concat(deprecationWarningAnnotations); } -// General utility for mapping-and-concatenating (aka flat-mapping). -function mapCat( - array: ReadonlyArray, - mapper: (item: T) => Array, -): Array { - return Array.prototype.concat.apply([], array.map(mapper)); -} - function annotations( error: GraphQLError, severity: DiagnosticSeverity,