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

FieldsOnCorrectTypeRule: improve type coverage #2404

Merged
merged 1 commit into from
Jan 27, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/polyfills/arrayFrom.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import { SYMBOL_ITERATOR } from './symbols';

declare function arrayFrom<T>(arrayLike: Iterable<T>): Array<T>;
// eslint-disable-next-line no-redeclare
declare function arrayFrom<T: mixed>(
arrayLike: mixed,
mapFn?: (elem: mixed, index: number) => T,
Expand Down
10 changes: 7 additions & 3 deletions src/validation/rules/FieldsOnCorrectTypeRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { type ASTVisitor } from '../../language/visitor';
import { type GraphQLSchema } from '../../type/schema';
import {
type GraphQLOutputType,
type GraphQLObjectType,
type GraphQLInterfaceType,
isObjectType,
isInterfaceType,
isAbstractType,
Expand Down Expand Up @@ -79,7 +81,9 @@ function getSuggestedTypeNames(
return [];
}

const suggestedTypes = new Set();
const suggestedTypes: Set<
GraphQLObjectType | GraphQLInterfaceType,
> = new Set();
const usageCount = Object.create(null);
for (const possibleType of schema.getPossibleTypes(type)) {
if (!possibleType.getFields()[fieldName]) {
Expand Down Expand Up @@ -111,10 +115,10 @@ function getSuggestedTypeNames(
}

// Suggest super types first followed by subtypes
if (isAbstractType(typeA) && schema.isSubType(typeA, typeB)) {
if (isInterfaceType(typeA) && schema.isSubType(typeA, typeB)) {
return -1;
}
if (isAbstractType(typeB) && schema.isSubType(typeB, typeA)) {
if (isInterfaceType(typeB) && schema.isSubType(typeB, typeA)) {
return 1;
}

Expand Down