Skip to content

Commit 98751e4

Browse files
authored
Strict const args (#1233)
Now that we're `@flow strict` we can remove some unnatural patterns for telling flow that we expect function args to be const.
1 parent 5fe3926 commit 98751e4

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

src/utilities/astFromValue.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,54 +42,51 @@ import { GraphQLID } from '../type/scalars';
4242
*
4343
*/
4444
export function astFromValue(value: mixed, type: GraphQLInputType): ?ValueNode {
45-
// Ensure flow knows that we treat function params as const.
46-
const _value = value;
47-
4845
if (isNonNullType(type)) {
49-
const astValue = astFromValue(_value, type.ofType);
46+
const astValue = astFromValue(value, type.ofType);
5047
if (astValue && astValue.kind === Kind.NULL) {
5148
return null;
5249
}
5350
return astValue;
5451
}
5552

5653
// only explicit null, not undefined, NaN
57-
if (_value === null) {
54+
if (value === null) {
5855
return { kind: Kind.NULL };
5956
}
6057

6158
// undefined, NaN
62-
if (isInvalid(_value)) {
59+
if (isInvalid(value)) {
6360
return null;
6461
}
6562

6663
// Convert JavaScript array to GraphQL list. If the GraphQLType is a list, but
6764
// the value is not an array, convert the value using the list's item type.
6865
if (isListType(type)) {
6966
const itemType = type.ofType;
70-
if (isCollection(_value)) {
67+
if (isCollection(value)) {
7168
const valuesNodes = [];
72-
forEach((_value: any), item => {
69+
forEach((value: any), item => {
7370
const itemNode = astFromValue(item, itemType);
7471
if (itemNode) {
7572
valuesNodes.push(itemNode);
7673
}
7774
});
7875
return { kind: Kind.LIST, values: valuesNodes };
7976
}
80-
return astFromValue(_value, itemType);
77+
return astFromValue(value, itemType);
8178
}
8279

8380
// Populate the fields of the input object by creating ASTs from each value
8481
// in the JavaScript object according to the fields in the input type.
8582
if (isInputObjectType(type)) {
86-
if (_value === null || typeof _value !== 'object') {
83+
if (value === null || typeof value !== 'object') {
8784
return null;
8885
}
8986
const fields = objectValues(type.getFields());
9087
const fieldNodes = [];
9188
fields.forEach(field => {
92-
const fieldValue = astFromValue(_value[field.name], field.type);
89+
const fieldValue = astFromValue(value[field.name], field.type);
9390
if (fieldValue) {
9491
fieldNodes.push({
9592
kind: Kind.OBJECT_FIELD,
@@ -104,7 +101,7 @@ export function astFromValue(value: mixed, type: GraphQLInputType): ?ValueNode {
104101
if (isScalarType(type) || isEnumType(type)) {
105102
// Since value is an internally represented value, it must be serialized
106103
// to an externally represented value before converting into an AST.
107-
const serialized = type.serialize(_value);
104+
const serialized = type.serialize(value);
108105
if (isNullish(serialized)) {
109106
return null;
110107
}

src/utilities/typeComparators.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,29 +105,26 @@ export function doTypesOverlap(
105105
typeA: GraphQLCompositeType,
106106
typeB: GraphQLCompositeType,
107107
): boolean {
108-
// So flow is aware this is constant
109-
const _typeB = typeB;
110-
111108
// Equivalent types overlap
112-
if (typeA === _typeB) {
109+
if (typeA === typeB) {
113110
return true;
114111
}
115112

116113
if (isAbstractType(typeA)) {
117-
if (isAbstractType(_typeB)) {
114+
if (isAbstractType(typeB)) {
118115
// If both types are abstract, then determine if there is any intersection
119116
// between possible concrete types of each.
120117
return schema
121118
.getPossibleTypes(typeA)
122-
.some(type => schema.isPossibleType(_typeB, type));
119+
.some(type => schema.isPossibleType(typeB, type));
123120
}
124121
// Determine if the latter type is a possible concrete type of the former.
125-
return schema.isPossibleType(typeA, _typeB);
122+
return schema.isPossibleType(typeA, typeB);
126123
}
127124

128-
if (isAbstractType(_typeB)) {
125+
if (isAbstractType(typeB)) {
129126
// Determine if the former type is a possible concrete type of the latter.
130-
return schema.isPossibleType(_typeB, typeA);
127+
return schema.isPossibleType(typeB, typeA);
131128
}
132129

133130
// Otherwise the types do not overlap.

0 commit comments

Comments
 (0)