Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove 'find' polyfill #2907

Merged
merged 1 commit into from Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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