Skip to content

Commit c44ea4f

Browse files
dimaMachinaacao
authored andcommitted
remove mapCat() in favor of Array#flatMap()
1 parent 695100b commit c44ea4f

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

.changeset/plenty-candles-shave.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'graphql-language-service': patch
3+
---
4+
5+
remove `mapCat()` in favor of `Array#flatMap()`

packages/graphql-language-service/src/interface/getDiagnostics.ts

+11-14
Original file line numberDiff line numberDiff line change
@@ -113,27 +113,24 @@ export function validateQuery(
113113
return [];
114114
}
115115

116-
const validationErrorAnnotations = mapCat(
117-
validateWithCustomRules(schema, ast, customRules, isRelayCompatMode),
118-
error => annotations(error, DIAGNOSTIC_SEVERITY.Error, 'Validation'),
116+
const validationErrorAnnotations = validateWithCustomRules(
117+
schema,
118+
ast,
119+
customRules,
120+
isRelayCompatMode,
121+
).flatMap(error =>
122+
annotations(error, DIAGNOSTIC_SEVERITY.Error, 'Validation'),
119123
);
120124

121125
// TODO: detect if > [email protected], and use the new rule for this.
122-
const deprecationWarningAnnotations = mapCat(
123-
validate(schema, ast, [NoDeprecatedCustomRule]),
124-
error => annotations(error, DIAGNOSTIC_SEVERITY.Warning, 'Deprecation'),
126+
const deprecationWarningAnnotations = validate(schema, ast, [
127+
NoDeprecatedCustomRule,
128+
]).flatMap(error =>
129+
annotations(error, DIAGNOSTIC_SEVERITY.Warning, 'Deprecation'),
125130
);
126131
return validationErrorAnnotations.concat(deprecationWarningAnnotations);
127132
}
128133

129-
// General utility for mapping-and-concatenating (aka flat-mapping).
130-
function mapCat<T>(
131-
array: ReadonlyArray<T>,
132-
mapper: (item: T) => Array<any>,
133-
): Array<any> {
134-
return Array.prototype.concat.apply([], array.map(mapper));
135-
}
136-
137134
function annotations(
138135
error: GraphQLError,
139136
severity: DiagnosticSeverity,

0 commit comments

Comments
 (0)