Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove mapCat() in favor of Array#flatMap()
Browse files Browse the repository at this point in the history
dimaMachina committed Dec 2, 2022
1 parent 695100b commit 19f0f09
Showing 2 changed files with 16 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/plenty-candles-shave.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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,

0 comments on commit 19f0f09

Please sign in to comment.