Skip to content

Commit

Permalink
Remove 'find' polyfill (graphql#2907)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Feb 20, 2021
1 parent eea7cac commit 3fc0b20
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 39 deletions.
12 changes: 4 additions & 8 deletions 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';
Expand Down Expand Up @@ -249,12 +247,10 @@ export function getDirectiveValues(
node: { +directives?: $ReadOnlyArray<DirectiveNode>, ... },
variableValues?: ?ObjMap<mixed>,
): 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);
Expand Down
19 changes: 0 additions & 19 deletions src/polyfills/find.js

This file was deleted.

3 changes: 1 addition & 2 deletions 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';
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions src/type/validate.js
@@ -1,4 +1,3 @@
import find from '../polyfills/find';
import objectValues from '../polyfills/objectValues';

import inspect from '../jsutils/inspect';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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}.`,
Expand Down
5 changes: 1 addition & 4 deletions 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';
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions 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';
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3fc0b20

Please sign in to comment.