Skip to content

Commit 70f008e

Browse files
IvanGoncharovleebyron
authored andcommitted
Remove redundant Flow type casts (#1278)
1 parent 1fbd7ec commit 70f008e

File tree

4 files changed

+15
-29
lines changed

4 files changed

+15
-29
lines changed

src/execution/values.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import type { GraphQLSchema } from '../type/schema';
2424
import type {
2525
FieldNode,
2626
DirectiveNode,
27-
VariableNode,
2827
VariableDefinitionNode,
2928
} from '../language/ast';
3029

@@ -139,7 +138,7 @@ export function getArgumentValues(
139138
);
140139
}
141140
} else if (argumentNode.value.kind === Kind.VARIABLE) {
142-
const variableName = (argumentNode.value: VariableNode).name.value;
141+
const variableName = argumentNode.value.name.value;
143142
if (
144143
variableValues &&
145144
Object.prototype.hasOwnProperty.call(variableValues, variableName) &&

src/type/__tests__/definition-test.js

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,35 +120,31 @@ describe('Type System: Example', () => {
120120

121121
expect(BlogSchema.getQueryType()).to.equal(BlogQuery);
122122

123-
const articleField = BlogQuery.getFields()[('article': string)];
123+
const articleField = BlogQuery.getFields()['article'];
124124
expect(articleField && articleField.type).to.equal(BlogArticle);
125125
expect(articleField && articleField.type.name).to.equal('Article');
126126
expect(articleField && articleField.name).to.equal('article');
127127

128128
const articleFieldType = articleField ? articleField.type : null;
129129

130130
const titleField =
131-
isObjectType(articleFieldType) &&
132-
articleFieldType.getFields()[('title': string)];
131+
isObjectType(articleFieldType) && articleFieldType.getFields()['title'];
133132
expect(titleField && titleField.name).to.equal('title');
134133
expect(titleField && titleField.type).to.equal(GraphQLString);
135134
expect(titleField && titleField.type.name).to.equal('String');
136135

137136
const authorField =
138-
isObjectType(articleFieldType) &&
139-
articleFieldType.getFields()[('author': string)];
137+
isObjectType(articleFieldType) && articleFieldType.getFields()['author'];
140138

141139
const authorFieldType = authorField ? authorField.type : null;
142140
const recentArticleField =
143141
isObjectType(authorFieldType) &&
144-
authorFieldType.getFields()[('recentArticle': string)];
142+
authorFieldType.getFields()['recentArticle'];
145143

146144
expect(recentArticleField && recentArticleField.type).to.equal(BlogArticle);
147145

148-
const feedField = BlogQuery.getFields()[('feed': string)];
149-
expect(feedField && (feedField.type: GraphQLList).ofType).to.equal(
150-
BlogArticle,
151-
);
146+
const feedField = BlogQuery.getFields()['feed'];
147+
expect(feedField && feedField.type.ofType).to.equal(BlogArticle);
152148
expect(feedField && feedField.name).to.equal('feed');
153149
});
154150

@@ -160,7 +156,7 @@ describe('Type System: Example', () => {
160156

161157
expect(BlogSchema.getMutationType()).to.equal(BlogMutation);
162158

163-
const writeMutation = BlogMutation.getFields()[('writeArticle': string)];
159+
const writeMutation = BlogMutation.getFields()['writeArticle'];
164160
expect(writeMutation && writeMutation.type).to.equal(BlogArticle);
165161
expect(writeMutation && writeMutation.type.name).to.equal('Article');
166162
expect(writeMutation && writeMutation.name).to.equal('writeArticle');
@@ -174,7 +170,7 @@ describe('Type System: Example', () => {
174170

175171
expect(BlogSchema.getSubscriptionType()).to.equal(BlogSubscription);
176172

177-
const sub = BlogSubscription.getFields()[('articleSubscribe': string)];
173+
const sub = BlogSubscription.getFields()['articleSubscribe'];
178174
expect(sub && sub.type).to.equal(BlogArticle);
179175
expect(sub && sub.type.name).to.equal('Article');
180176
expect(sub && sub.name).to.equal('articleSubscribe');

src/type/schema.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import type {
1919
GraphQLNamedType,
2020
GraphQLAbstractType,
2121
GraphQLObjectType,
22-
GraphQLInterfaceType,
2322
} from './definition';
2423
import type { SchemaDefinitionNode } from '../language/ast';
2524
import {
@@ -191,7 +190,7 @@ export class GraphQLSchema {
191190
if (isUnionType(abstractType)) {
192191
return abstractType.getTypes();
193192
}
194-
return this._implementations[(abstractType: GraphQLInterfaceType).name];
193+
return this._implementations[abstractType.name];
195194
}
196195

197196
isPossibleType(

src/utilities/valueFromAST.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ import {
2020
isNonNullType,
2121
} from '../type/definition';
2222
import type { GraphQLInputType } from '../type/definition';
23-
import type {
24-
ValueNode,
25-
VariableNode,
26-
ListValueNode,
27-
ObjectValueNode,
28-
} from '../language/ast';
23+
import type { ValueNode } from '../language/ast';
2924

3025
/**
3126
* Produces a JavaScript value given a GraphQL Value AST.
@@ -71,7 +66,7 @@ export function valueFromAST(
7166
}
7267

7368
if (valueNode.kind === Kind.VARIABLE) {
74-
const variableName = (valueNode: VariableNode).name.value;
69+
const variableName = valueNode.name.value;
7570
if (!variables || isInvalid(variables[variableName])) {
7671
// No valid return value.
7772
return;
@@ -86,7 +81,7 @@ export function valueFromAST(
8681
const itemType = type.ofType;
8782
if (valueNode.kind === Kind.LIST) {
8883
const coercedValues = [];
89-
const itemNodes = (valueNode: ListValueNode).values;
84+
const itemNodes = valueNode.values;
9085
for (let i = 0; i < itemNodes.length; i++) {
9186
if (isMissingVariable(itemNodes[i], variables)) {
9287
// If an array contains a missing variable, it is either coerced to
@@ -117,10 +112,7 @@ export function valueFromAST(
117112
return; // Invalid: intentionally return no value.
118113
}
119114
const coercedObj = Object.create(null);
120-
const fieldNodes = keyMap(
121-
(valueNode: ObjectValueNode).fields,
122-
field => field.name.value,
123-
);
115+
const fieldNodes = keyMap(valueNode.fields, field => field.name.value);
124116
const fields = objectValues(type.getFields());
125117
for (let i = 0; i < fields.length; i++) {
126118
const field = fields[i];
@@ -178,6 +170,6 @@ export function valueFromAST(
178170
function isMissingVariable(valueNode, variables) {
179171
return (
180172
valueNode.kind === Kind.VARIABLE &&
181-
(!variables || isInvalid(variables[(valueNode: VariableNode).name.value]))
173+
(!variables || isInvalid(variables[valueNode.name.value]))
182174
);
183175
}

0 commit comments

Comments
 (0)