Skip to content

Commit

Permalink
Remove polyfills for 'Object.values' & 'Object.entries' (graphql#2919)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Feb 20, 2021
1 parent 1d84a8a commit 3638c2d
Show file tree
Hide file tree
Showing 25 changed files with 2,603 additions and 95 deletions.
1 change: 1 addition & 0 deletions .flowconfig
Expand Up @@ -37,6 +37,7 @@ module.use_strict=true
babel_loose_array_spread=true
experimental.const_params=true
include_warnings=true
no_flowlib=true

[version]
^0.142.0
1 change: 0 additions & 1 deletion .nycrc.yml
Expand Up @@ -2,7 +2,6 @@ all: true
include:
- 'src/'
exclude:
- 'src/polyfills'
- '**/*-fuzz.js'
- '**/*.d.ts'
clean: true
Expand Down
2 changes: 2 additions & 0 deletions .prettierignore
@@ -1,3 +1,5 @@
/flow-typed

# Copied from '.gitignore', please keep it in sync.
/.eslintcache
/node_modules
Expand Down
2,565 changes: 2,562 additions & 3 deletions flow-typed/core.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions flow-typed/node.js
@@ -0,0 +1,5 @@
declare class Process extends events$EventEmitter {
env : { [key: string] : string | void, ... };
}

declare var process: Process;
4 changes: 1 addition & 3 deletions src/jsutils/mapValue.js
@@ -1,5 +1,3 @@
import { objectEntries } from '../polyfills/objectEntries';

import type { ObjMap } from './ObjMap';

/**
Expand All @@ -12,7 +10,7 @@ export function mapValue<T, V>(
): ObjMap<V> {
const result = Object.create(null);

for (const [key, value] of objectEntries(map)) {
for (const [key, value] of Object.entries(map)) {
result[key] = fn(value, key);
}
return result;
Expand Down
4 changes: 1 addition & 3 deletions src/jsutils/toObjMap.js
@@ -1,5 +1,3 @@
import { objectEntries } from '../polyfills/objectEntries';

import type {
ObjMap,
ObjMapLike,
Expand All @@ -18,7 +16,7 @@ export function toObjMap(obj) {
}

const map = Object.create(null);
for (const [key, value] of objectEntries(obj)) {
for (const [key, value] of Object.entries(obj)) {
map[key] = value;
}
return map;
Expand Down
8 changes: 0 additions & 8 deletions src/polyfills/README.md

This file was deleted.

8 changes: 0 additions & 8 deletions src/polyfills/objectEntries.js

This file was deleted.

8 changes: 0 additions & 8 deletions src/polyfills/objectValues.js

This file was deleted.

6 changes: 2 additions & 4 deletions src/type/definition.js
@@ -1,5 +1,3 @@
import { objectEntries } from '../polyfills/objectEntries';

import type { Path } from '../jsutils/Path';
import type { PromiseOrValue } from '../jsutils/PromiseOrValue';
import type {
Expand Down Expand Up @@ -811,7 +809,7 @@ function defineFieldMap<TSource, TContext>(
`${config.name}.${fieldName} args must be an object with argument names as keys.`,
);

const args = objectEntries(argsConfig).map(([argName, argConfig]) => ({
const args = Object.entries(argsConfig).map(([argName, argConfig]) => ({
name: argName,
description: argConfig.description,
type: argConfig.type,
Expand Down Expand Up @@ -1388,7 +1386,7 @@ function defineEnumValues(
isPlainObj(valueMap),
`${typeName} values must be an object with value names as keys.`,
);
return objectEntries(valueMap).map(([valueName, valueConfig]) => {
return Object.entries(valueMap).map(([valueName, valueConfig]) => {
devAssert(
isPlainObj(valueConfig),
`${typeName}.${valueName} must refer to an object with a "value" key ` +
Expand Down
4 changes: 1 addition & 3 deletions src/type/directives.js
@@ -1,5 +1,3 @@
import { objectEntries } from '../polyfills/objectEntries';

import type { ReadOnlyObjMap, ReadOnlyObjMapLike } from '../jsutils/ObjMap';
import { inspect } from '../jsutils/inspect';
import { toObjMap } from '../jsutils/toObjMap';
Expand Down Expand Up @@ -71,7 +69,7 @@ export class GraphQLDirective {
`@${config.name} args must be an object with argument names as keys.`,
);

this.args = objectEntries(args).map(([argName, argConfig]) => ({
this.args = Object.entries(args).map(([argName, argConfig]) => ({
name: argName,
description: argConfig.description,
type: argConfig.type,
Expand Down
8 changes: 3 additions & 5 deletions src/type/introspection.js
@@ -1,5 +1,3 @@
import { objectValues } from '../polyfills/objectValues';

import { inspect } from '../jsutils/inspect';
import { invariant } from '../jsutils/invariant';

Expand Down Expand Up @@ -48,7 +46,7 @@ export const __Schema = new GraphQLObjectType({
description: 'A list of all types supported by this server.',
type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(__Type))),
resolve(schema) {
return objectValues(schema.getTypeMap());
return Object.values(schema.getTypeMap());
},
},
queryType: {
Expand Down Expand Up @@ -255,7 +253,7 @@ export const __Type = new GraphQLObjectType({
},
resolve(type, { includeDeprecated }) {
if (isObjectType(type) || isInterfaceType(type)) {
const fields = objectValues(type.getFields());
const fields = Object.values(type.getFields());
return includeDeprecated
? fields
: fields.filter((field) => field.deprecationReason == null);
Expand Down Expand Up @@ -302,7 +300,7 @@ export const __Type = new GraphQLObjectType({
},
resolve(type, { includeDeprecated }) {
if (isInputObjectType(type)) {
const values = objectValues(type.getFields());
const values = Object.values(type.getFields());
return includeDeprecated
? values
: values.filter((field) => field.deprecationReason == null);
Expand Down
8 changes: 3 additions & 5 deletions src/type/schema.js
@@ -1,5 +1,3 @@
import { objectValues } from '../polyfills/objectValues';

import type {
ObjMap,
ReadOnlyObjMap,
Expand Down Expand Up @@ -335,7 +333,7 @@ export class GraphQLSchema {
query: this.getQueryType(),
mutation: this.getMutationType(),
subscription: this.getSubscriptionType(),
types: objectValues(this.getTypeMap()),
types: Object.values(this.getTypeMap()),
directives: this.getDirectives().slice(),
extensions: this.extensions,
astNode: this.astNode,
Expand Down Expand Up @@ -406,14 +404,14 @@ function collectReferencedTypes(
collectReferencedTypes(interfaceType, typeSet);
}

for (const field of objectValues(namedType.getFields())) {
for (const field of Object.values(namedType.getFields())) {
collectReferencedTypes(field.type, typeSet);
for (const arg of field.args) {
collectReferencedTypes(arg.type, typeSet);
}
}
} else if (isInputObjectType(namedType)) {
for (const field of objectValues(namedType.getFields())) {
for (const field of Object.values(namedType.getFields())) {
collectReferencedTypes(field.type, typeSet);
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/type/validate.js
@@ -1,5 +1,3 @@
import { objectValues } from '../polyfills/objectValues';

import { inspect } from '../jsutils/inspect';

import { GraphQLError } from '../error/GraphQLError';
Expand Down Expand Up @@ -214,7 +212,7 @@ function validateTypes(context: SchemaValidationContext): void {
context,
);
const typeMap = context.schema.getTypeMap();
for (const type of objectValues(typeMap)) {
for (const type of Object.values(typeMap)) {
// Ensure all provided types are in fact GraphQL type.
if (!isNamedType(type)) {
context.reportError(
Expand Down Expand Up @@ -261,7 +259,7 @@ function validateFields(
context: SchemaValidationContext,
type: GraphQLObjectType | GraphQLInterfaceType,
): void {
const fields = objectValues(type.getFields());
const fields = Object.values(type.getFields());

// Objects and Interfaces both must define one or more fields.
if (fields.length === 0) {
Expand Down Expand Up @@ -360,7 +358,7 @@ function validateTypeImplementsInterface(
const typeFieldMap = type.getFields();

// Assert each interface field is implemented.
for (const ifaceField of objectValues(iface.getFields())) {
for (const ifaceField of Object.values(iface.getFields())) {
const fieldName = ifaceField.name;
const typeField = typeFieldMap[fieldName];

Expand Down Expand Up @@ -523,7 +521,7 @@ function validateInputFields(
context: SchemaValidationContext,
inputObj: GraphQLInputObjectType,
): void {
const fields = objectValues(inputObj.getFields());
const fields = Object.values(inputObj.getFields());

if (fields.length === 0) {
context.reportError(
Expand Down Expand Up @@ -586,7 +584,7 @@ function createInputObjectCircularRefsValidator(
visitedTypes[inputObj.name] = true;
fieldPathIndexByTypeName[inputObj.name] = fieldPath.length;

const fields = objectValues(inputObj.getFields());
const fields = Object.values(inputObj.getFields());
for (const field of fields) {
if (isNonNullType(field.type) && isInputObjectType(field.type.ofType)) {
const fieldType = field.type.ofType;
Expand Down
4 changes: 1 addition & 3 deletions src/utilities/astFromValue.js
@@ -1,5 +1,3 @@
import { objectValues } from '../polyfills/objectValues';

import { inspect } from '../jsutils/inspect';
import { invariant } from '../jsutils/invariant';
import { isObjectLike } from '../jsutils/isObjectLike';
Expand Down Expand Up @@ -84,7 +82,7 @@ export function astFromValue(value: mixed, type: GraphQLInputType): ?ValueNode {
return null;
}
const fieldNodes = [];
for (const field of objectValues(type.getFields())) {
for (const field of Object.values(type.getFields())) {
const fieldValue = astFromValue(value[field.name], field.type);
if (fieldValue) {
fieldNodes.push({
Expand Down
4 changes: 1 addition & 3 deletions src/utilities/buildClientSchema.js
@@ -1,5 +1,3 @@
import { objectValues } from '../polyfills/objectValues';

import { inspect } from '../jsutils/inspect';
import { devAssert } from '../jsutils/devAssert';
import { keyValMap } from '../jsutils/keyValMap';
Expand Down Expand Up @@ -116,7 +114,7 @@ export function buildClientSchema(
query: queryType,
mutation: mutationType,
subscription: subscriptionType,
types: objectValues(typeMap),
types: Object.values(typeMap),
directives,
assumeValid: options?.assumeValid,
});
Expand Down
4 changes: 1 addition & 3 deletions src/utilities/coerceInputValue.js
@@ -1,5 +1,3 @@
import { objectValues } from '../polyfills/objectValues';

import type { Path } from '../jsutils/Path';
import { inspect } from '../jsutils/inspect';
import { invariant } from '../jsutils/invariant';
Expand Down Expand Up @@ -100,7 +98,7 @@ function coerceInputValueImpl(
const coercedValue = {};
const fieldDefs = type.getFields();

for (const field of objectValues(fieldDefs)) {
for (const field of Object.values(fieldDefs)) {
const fieldValue = inputValue[field.name];

if (fieldValue === undefined) {
Expand Down
4 changes: 1 addition & 3 deletions src/utilities/extendSchema.js
@@ -1,5 +1,3 @@
import { objectValues } from '../polyfills/objectValues';

import { keyMap } from '../jsutils/keyMap';
import { inspect } from '../jsutils/inspect';
import { mapValue } from '../jsutils/mapValue';
Expand Down Expand Up @@ -205,7 +203,7 @@ export function extendSchemaImpl(
return {
description: schemaDef?.description?.value,
...operationTypes,
types: objectValues(typeMap),
types: Object.values(typeMap),
directives: [
...schemaConfig.directives.map(replaceDirective),
...directiveDefs.map(buildDirective),
Expand Down
14 changes: 6 additions & 8 deletions src/utilities/findBreakingChanges.js
@@ -1,5 +1,3 @@
import { objectValues } from '../polyfills/objectValues';

import { keyMap } from '../jsutils/keyMap';
import { inspect } from '../jsutils/inspect';
import { invariant } from '../jsutils/invariant';
Expand Down Expand Up @@ -177,8 +175,8 @@ function findTypeChanges(
const schemaChanges = [];

const typesDiff = diff(
objectValues(oldSchema.getTypeMap()),
objectValues(newSchema.getTypeMap()),
Object.values(oldSchema.getTypeMap()),
Object.values(newSchema.getTypeMap()),
);

for (const oldType of typesDiff.removed) {
Expand Down Expand Up @@ -226,8 +224,8 @@ function findInputObjectTypeChanges(
): Array<BreakingChange | DangerousChange> {
const schemaChanges = [];
const fieldsDiff = diff(
objectValues(oldType.getFields()),
objectValues(newType.getFields()),
Object.values(oldType.getFields()),
Object.values(newType.getFields()),
);

for (const newField of fieldsDiff.added) {
Expand Down Expand Up @@ -347,8 +345,8 @@ function findFieldChanges(
): Array<BreakingChange | DangerousChange> {
const schemaChanges = [];
const fieldsDiff = diff(
objectValues(oldType.getFields()),
objectValues(newType.getFields()),
Object.values(oldType.getFields()),
Object.values(newType.getFields()),
);

for (const oldField of fieldsDiff.removed) {
Expand Down
4 changes: 1 addition & 3 deletions src/utilities/lexicographicSortSchema.js
@@ -1,5 +1,3 @@
import { objectValues } from '../polyfills/objectValues';

import type { ObjMap } from '../jsutils/ObjMap';
import { inspect } from '../jsutils/inspect';
import { invariant } from '../jsutils/invariant';
Expand Down Expand Up @@ -49,7 +47,7 @@ export function lexicographicSortSchema(schema: GraphQLSchema): GraphQLSchema {

return new GraphQLSchema({
...schemaConfig,
types: objectValues(typeMap),
types: Object.values(typeMap),
directives: sortByName(schemaConfig.directives).map(sortDirective),
query: replaceMaybeType(schemaConfig.query),
mutation: replaceMaybeType(schemaConfig.mutation),
Expand Down
8 changes: 3 additions & 5 deletions src/utilities/printSchema.js
@@ -1,5 +1,3 @@
import { objectValues } from '../polyfills/objectValues';

import { inspect } from '../jsutils/inspect';
import { invariant } from '../jsutils/invariant';

Expand Down Expand Up @@ -58,7 +56,7 @@ function printFilteredSchema(
typeFilter: (type: GraphQLNamedType) => boolean,
): string {
const directives = schema.getDirectives().filter(directiveFilter);
const types = objectValues(schema.getTypeMap()).filter(typeFilter);
const types = Object.values(schema.getTypeMap()).filter(typeFilter);

return (
[printSchemaDefinition(schema)]
Expand Down Expand Up @@ -206,14 +204,14 @@ function printEnum(type: GraphQLEnumType): string {
}

function printInputObject(type: GraphQLInputObjectType): string {
const fields = objectValues(type.getFields()).map(
const fields = Object.values(type.getFields()).map(
(f, i) => printDescription(f, ' ', !i) + ' ' + printInputValue(f),
);
return printDescription(type) + `input ${type.name}` + printBlock(fields);
}

function printFields(type: GraphQLObjectType | GraphQLInterfaceType): string {
const fields = objectValues(type.getFields()).map(
const fields = Object.values(type.getFields()).map(
(f, i) =>
printDescription(f, ' ', !i) +
' ' +
Expand Down

0 comments on commit 3638c2d

Please sign in to comment.