From ffe689fe1bf719a1ef10ba366abb958a9dc4f265 Mon Sep 17 00:00:00 2001 From: Ivan Goncharov Date: Sun, 30 Aug 2020 01:33:57 +0300 Subject: [PATCH] Remove 'find' polyfill --- src/execution/values.js | 12 ++++-------- src/polyfills/find.js | 19 ------------------- src/type/schema.js | 3 +-- src/type/validate.js | 5 ++--- src/utilities/TypeInfo.js | 5 +---- .../rules/OverlappingFieldsCanBeMergedRule.js | 4 +--- 6 files changed, 9 insertions(+), 39 deletions(-) delete mode 100644 src/polyfills/find.js diff --git a/src/execution/values.js b/src/execution/values.js index cfe9a4e0d7..51c0678098 100644 --- a/src/execution/values.js +++ b/src/execution/values.js @@ -1,5 +1,3 @@ -import find from '../polyfills/find'; - import type { ObjMap } from '../jsutils/ObjMap'; import keyMap from '../jsutils/keyMap'; import inspect from '../jsutils/inspect'; @@ -249,12 +247,10 @@ export function getDirectiveValues( node: { +directives?: $ReadOnlyArray, ... }, variableValues?: ?ObjMap, ): void | { [argument: string]: mixed, ... } { - const directiveNode = - node.directives && - find( - node.directives, - (directive) => directive.name.value === directiveDef.name, - ); + // istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203') + const directiveNode = node.directives?.find( + (directive) => directive.name.value === directiveDef.name, + ); if (directiveNode) { return getArgumentValues(directiveDef, directiveNode, variableValues); diff --git a/src/polyfills/find.js b/src/polyfills/find.js deleted file mode 100644 index 403ba0f2b7..0000000000 --- a/src/polyfills/find.js +++ /dev/null @@ -1,19 +0,0 @@ -declare function find( - list: $ReadOnlyArray, - predicate: (item: T) => boolean, -): T | void; - -/* eslint-disable no-redeclare */ -// $FlowFixMe[name-already-bound] -const find = Array.prototype.find - ? function (list, predicate) { - return Array.prototype.find.call(list, predicate); - } - : function (list, predicate) { - for (const value of list) { - if (predicate(value)) { - return value; - } - } - }; -export default find; diff --git a/src/type/schema.js b/src/type/schema.js index 87a2f47707..5e07980649 100644 --- a/src/type/schema.js +++ b/src/type/schema.js @@ -1,4 +1,3 @@ -import find from '../polyfills/find'; import arrayFrom from '../polyfills/arrayFrom'; import objectValues from '../polyfills/objectValues'; import { SYMBOL_TO_STRING_TAG } from '../polyfills/symbols'; @@ -329,7 +328,7 @@ export class GraphQLSchema { } getDirective(name: string): ?GraphQLDirective { - return find(this.getDirectives(), (directive) => directive.name === name); + return this.getDirectives().find((directive) => directive.name === name); } toConfig(): GraphQLSchemaNormalizedConfig { diff --git a/src/type/validate.js b/src/type/validate.js index a2ddfe4a43..f0075e2b9e 100644 --- a/src/type/validate.js +++ b/src/type/validate.js @@ -1,4 +1,3 @@ -import find from '../polyfills/find'; import objectValues from '../polyfills/objectValues'; import inspect from '../jsutils/inspect'; @@ -393,7 +392,7 @@ function validateTypeImplementsInterface( // Assert each interface field arg is implemented. for (const ifaceArg of ifaceField.args) { const argName = ifaceArg.name; - const typeArg = find(typeField.args, (arg) => arg.name === argName); + const typeArg = typeField.args.find((arg) => arg.name === argName); // Assert interface field arg exists on object field. if (!typeArg) { @@ -428,7 +427,7 @@ function validateTypeImplementsInterface( // Assert additional arguments must not be required. for (const typeArg of typeField.args) { const argName = typeArg.name; - const ifaceArg = find(ifaceField.args, (arg) => arg.name === argName); + const ifaceArg = ifaceField.args.find((arg) => arg.name === argName); if (!ifaceArg && isRequiredArgument(typeArg)) { context.reportError( `Object field ${type.name}.${fieldName} includes required argument ${argName} that is missing from the Interface field ${iface.name}.${fieldName}.`, diff --git a/src/utilities/TypeInfo.js b/src/utilities/TypeInfo.js index f18b03d68e..c72684a742 100644 --- a/src/utilities/TypeInfo.js +++ b/src/utilities/TypeInfo.js @@ -1,5 +1,3 @@ -import find from '../polyfills/find'; - import type { Visitor } from '../language/visitor'; import type { ASTNode, ASTKindToNode, FieldNode } from '../language/ast'; import { Kind } from '../language/kinds'; @@ -204,8 +202,7 @@ export class TypeInfo { let argType: mixed; const fieldOrDirective = this.getDirective() ?? this.getFieldDef(); if (fieldOrDirective) { - argDef = find( - fieldOrDirective.args, + argDef = fieldOrDirective.args.find( (arg) => arg.name === node.name.value, ); if (argDef) { diff --git a/src/validation/rules/OverlappingFieldsCanBeMergedRule.js b/src/validation/rules/OverlappingFieldsCanBeMergedRule.js index 2d79dd098f..983f69099d 100644 --- a/src/validation/rules/OverlappingFieldsCanBeMergedRule.js +++ b/src/validation/rules/OverlappingFieldsCanBeMergedRule.js @@ -1,4 +1,3 @@ -import find from '../../polyfills/find'; import objectEntries from '../../polyfills/objectEntries'; import type { ObjMap } from '../../jsutils/ObjMap'; @@ -631,8 +630,7 @@ function sameArguments( return false; } return arguments1.every((argument1) => { - const argument2 = find( - arguments2, + const argument2 = arguments2.find( (argument) => argument.name.value === argument1.name.value, ); if (!argument2) {