Skip to content

Commit 126b572

Browse files
Convert a few cycles to use objectValues (#1649)
1 parent c032730 commit 126b572

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

src/type/schema.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ export class GraphQLSchema {
167167

168168
// Keep track of all implementations by interface name.
169169
this._implementations = Object.create(null);
170-
for (const typeName of Object.keys(this._typeMap)) {
171-
const type = this._typeMap[typeName];
170+
for (const type of objectValues(this._typeMap)) {
172171
if (isObjectType(type)) {
173172
for (const iface of type.getInterfaces()) {
174173
if (isInterfaceType(iface)) {

src/validation/rules/ValuesOfCorrectType.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import inspect from '../../jsutils/inspect';
2727
import isInvalid from '../../jsutils/isInvalid';
2828
import keyMap from '../../jsutils/keyMap';
2929
import orList from '../../jsutils/orList';
30+
import objectValues from '../../jsutils/objectValues';
3031
import suggestionList from '../../jsutils/suggestionList';
3132

3233
export function badValueMessage(
@@ -94,16 +95,14 @@ export function ValuesOfCorrectType(context: ValidationContext): ASTVisitor {
9495
return false; // Don't traverse further.
9596
}
9697
// Ensure every required field exists.
97-
const inputFields = type.getFields();
9898
const fieldNodeMap = keyMap(node.fields, field => field.name.value);
99-
for (const fieldName of Object.keys(inputFields)) {
100-
const fieldDef = inputFields[fieldName];
101-
const fieldNode = fieldNodeMap[fieldName];
99+
for (const fieldDef of objectValues(type.getFields())) {
100+
const fieldNode = fieldNodeMap[fieldDef.name];
102101
if (!fieldNode && isRequiredInputField(fieldDef)) {
103102
const typeStr = inspect(fieldDef.type);
104103
context.reportError(
105104
new GraphQLError(
106-
requiredFieldMessage(type.name, fieldName, typeStr),
105+
requiredFieldMessage(type.name, fieldDef.name, typeStr),
107106
node,
108107
),
109108
);

0 commit comments

Comments
 (0)