Skip to content

Commit

Permalink
remove mapCat() in favor of Array#flatMap()
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina authored and acao committed Dec 2, 2022
1 parent 695100b commit c44ea4f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-candles-shave.md
@@ -0,0 +1,5 @@
---
'graphql-language-service': patch
---

remove `mapCat()` in favor of `Array#flatMap()`
25 changes: 11 additions & 14 deletions packages/graphql-language-service/src/interface/getDiagnostics.ts
Expand Up @@ -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<T>(
array: ReadonlyArray<T>,
mapper: (item: T) => Array<any>,
): Array<any> {
return Array.prototype.concat.apply([], array.map(mapper));
}

function annotations(
error: GraphQLError,
severity: DiagnosticSeverity,
Expand Down

0 comments on commit c44ea4f

Please sign in to comment.