Skip to content

Commit

Permalink
Move $DisableFlowOnNegativeTest to more precise locations (#1664)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Jan 14, 2019
1 parent 8d7a5fd commit 6876587
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 80 deletions.
84 changes: 33 additions & 51 deletions src/type/__tests__/definition-test.js
Expand Up @@ -474,10 +474,10 @@ describe('Field config must be object', () => {
});

it('rejects an Object type field with undefined config', () => {
// $DisableFlowOnNegativeTest
const objType = new GraphQLObjectType({
name: 'SomeObject',
fields: {
// $DisableFlowOnNegativeTest
f: undefined,
},
});
Expand All @@ -487,9 +487,9 @@ describe('Field config must be object', () => {
});

it('rejects an Object type with incorrectly typed fields', () => {
// $DisableFlowOnNegativeTest
const objType = new GraphQLObjectType({
name: 'SomeObject',
// $DisableFlowOnNegativeTest
fields: [{ field: GraphQLString }],
});
expect(() => objType.getFields()).to.throw(
Expand All @@ -499,10 +499,10 @@ describe('Field config must be object', () => {
});

it('rejects an Object type with a field function that returns incorrect type', () => {
// $DisableFlowOnNegativeTest
const objType = new GraphQLObjectType({
name: 'SomeObject',
fields() {
// $DisableFlowOnNegativeTest
return [{ field: GraphQLString }];
},
});
Expand Down Expand Up @@ -530,12 +530,12 @@ describe('Field arg config must be object', () => {
});

it('rejects an Object type with incorrectly typed field args', () => {
// $DisableFlowOnNegativeTest
const objType = new GraphQLObjectType({
name: 'SomeObject',
fields: {
badField: {
type: GraphQLString,
// $DisableFlowOnNegativeTest
args: [{ badArg: GraphQLString }],
},
},
Expand All @@ -547,14 +547,11 @@ describe('Field arg config must be object', () => {

it('does not allow isDeprecated instead of deprecationReason on field', () => {
expect(() => {
// $DisableFlowOnNegativeTest
const OldObject = new GraphQLObjectType({
name: 'OldObject',
fields: {
field: {
type: GraphQLString,
isDeprecated: true,
},
// $DisableFlowOnNegativeTest
field: { type: GraphQLString, isDeprecated: true },
},
});

Expand Down Expand Up @@ -586,25 +583,25 @@ describe('Object interfaces must be array', () => {
});

it('rejects an Object type with incorrectly typed interfaces', () => {
// $DisableFlowOnNegativeTest
const objType = new GraphQLObjectType({
name: 'SomeObject',
fields: {},
// $DisableFlowOnNegativeTest
interfaces: {},
fields: { f: { type: GraphQLString } },
});
expect(() => objType.getInterfaces()).to.throw(
'SomeObject interfaces must be an Array or a function which returns an Array.',
);
});

it('rejects an Object type with interfaces as a function returning an incorrect type', () => {
// $DisableFlowOnNegativeTest
const objType = new GraphQLObjectType({
name: 'SomeObject',
fields: {},
// $DisableFlowOnNegativeTest
interfaces() {
return {};
},
fields: { f: { type: GraphQLString } },
});
expect(() => objType.getInterfaces()).to.throw(
'SomeObject interfaces must be an Array or a function which returns an Array.',
Expand Down Expand Up @@ -712,11 +709,11 @@ describe('Type System: Interface types must be resolvable', () => {
it('rejects an Interface type with an incorrect type for resolveType', () => {
expect(
() =>
// $DisableFlowOnNegativeTest
new GraphQLInterfaceType({
name: 'AnotherInterface',
fields: {},
// $DisableFlowOnNegativeTest
resolveType: {},
fields: { f: { type: GraphQLString } },
}),
).to.throw(
'AnotherInterface must provide "resolveType" as a function, but got: {}.',
Expand Down Expand Up @@ -766,11 +763,11 @@ describe('Type System: Union types must be resolvable', () => {
it('rejects an Interface type with an incorrect type for resolveType', () => {
expect(() =>
schemaWithFieldType(
// $DisableFlowOnNegativeTest
new GraphQLUnionType({
name: 'SomeUnion',
types: [],
// $DisableFlowOnNegativeTest
resolveType: {},
types: [ObjectWithIsTypeOf],
}),
),
).to.throw(
Expand All @@ -792,7 +789,6 @@ describe('Type System: Scalar types must be serializable', () => {
});

it('rejects a Scalar type not defining serialize', () => {
// $DisableFlowOnNegativeTest
expect(() =>
schemaWithFieldType(
// $DisableFlowOnNegativeTest
Expand All @@ -808,12 +804,11 @@ describe('Type System: Scalar types must be serializable', () => {
});

it('rejects a Scalar type defining serialize with an incorrect type', () => {
// $DisableFlowOnNegativeTest
expect(() =>
schemaWithFieldType(
// $DisableFlowOnNegativeTest
new GraphQLScalarType({
name: 'SomeScalar',
// $DisableFlowOnNegativeTest
serialize: {},
}),
),
Expand Down Expand Up @@ -868,11 +863,12 @@ describe('Type System: Scalar types must be serializable', () => {
it('rejects a Scalar type defining parseValue and parseLiteral with an incorrect type', () => {
expect(() =>
schemaWithFieldType(
// $DisableFlowOnNegativeTest
new GraphQLScalarType({
name: 'SomeScalar',
serialize: () => null,
// $DisableFlowOnNegativeTest
parseValue: {},
// $DisableFlowOnNegativeTest
parseLiteral: {},
}),
),
Expand All @@ -897,11 +893,11 @@ describe('Type System: Object types must be assertable', () => {
it('rejects an Object type with an incorrect type for isTypeOf', () => {
expect(() => {
schemaWithFieldType(
// $DisableFlowOnNegativeTest
new GraphQLObjectType({
name: 'AnotherObject',
fields: {},
// $DisableFlowOnNegativeTest
isTypeOf: {},
fields: { f: { type: GraphQLString } },
}),
);
}).to.throw(
Expand Down Expand Up @@ -947,12 +943,10 @@ describe('Type System: Union types must be array', () => {
it('rejects a Union type with incorrectly typed types', () => {
expect(() =>
schemaWithFieldType(
// $DisableFlowOnNegativeTest
new GraphQLUnionType({
name: 'SomeUnion',
types: {
ObjectType,
},
// $DisableFlowOnNegativeTest
types: { ObjectType },
}),
),
).to.throw(
Expand Down Expand Up @@ -986,9 +980,9 @@ describe('Type System: Input Objects must have fields', () => {
});

it('rejects an Input Object type with incorrect fields', () => {
// $DisableFlowOnNegativeTest
const inputObjType = new GraphQLInputObjectType({
name: 'SomeInputObject',
// $DisableFlowOnNegativeTest
fields: [],
});
expect(() => inputObjType.getFields()).to.throw(
Expand All @@ -998,12 +992,10 @@ describe('Type System: Input Objects must have fields', () => {
});

it('rejects an Input Object type with fields function that returns incorrect type', () => {
// $DisableFlowOnNegativeTest
const inputObjType = new GraphQLInputObjectType({
name: 'SomeInputObject',
fields() {
return [];
},
// $DisableFlowOnNegativeTest
fields: () => [],
});
expect(() => inputObjType.getFields()).to.throw(
'SomeInputObject fields must be an object with field names as keys or a ' +
Expand All @@ -1014,16 +1006,11 @@ describe('Type System: Input Objects must have fields', () => {

describe('Type System: Input Object fields must not have resolvers', () => {
it('rejects an Input Object type with resolvers', () => {
// $DisableFlowOnNegativeTest
const inputObjType = new GraphQLInputObjectType({
name: 'SomeInputObject',
fields: {
f: {
type: GraphQLString,
resolve: () => {
return 0;
},
},
// $DisableFlowOnNegativeTest
f: { type: GraphQLString, resolve: () => 0 },
},
});
expect(() => inputObjType.getFields()).to.throw(
Expand All @@ -1033,14 +1020,11 @@ describe('Type System: Input Object fields must not have resolvers', () => {
});

it('rejects an Input Object type with resolver constant', () => {
// $DisableFlowOnNegativeTest
const inputObjType = new GraphQLInputObjectType({
name: 'SomeInputObject',
fields: {
f: {
type: GraphQLString,
resolve: {},
},
// $DisableFlowOnNegativeTest
f: { type: GraphQLString, resolve: {} },
},
});
expect(() => inputObjType.getFields()).to.throw(
Expand Down Expand Up @@ -1078,9 +1062,9 @@ describe('Type System: Enum types must be well defined', () => {
it('rejects an Enum type with incorrectly typed values', () => {
const config = {
name: 'SomeEnum',
// $DisableFlowOnNegativeTest
values: [{ FOO: 10 }],
};
// $DisableFlowOnNegativeTest
expect(() => new GraphQLEnumType(config)).to.throw(
'SomeEnum values must be an object with value names as keys.',
);
Expand All @@ -1089,9 +1073,9 @@ describe('Type System: Enum types must be well defined', () => {
it('rejects an Enum type with missing value definition', () => {
const config = {
name: 'SomeEnum',
// $DisableFlowOnNegativeTest
values: { FOO: null },
};
// $DisableFlowOnNegativeTest
expect(() => new GraphQLEnumType(config)).to.throw(
'SomeEnum.FOO must refer to an object with a "value" key representing ' +
'an internal value but got: null.',
Expand All @@ -1101,9 +1085,9 @@ describe('Type System: Enum types must be well defined', () => {
it('rejects an Enum type with incorrectly typed value definition', () => {
const config = {
name: 'SomeEnum',
// $DisableFlowOnNegativeTest
values: { FOO: 10 },
};
// $DisableFlowOnNegativeTest
expect(() => new GraphQLEnumType(config)).to.throw(
'SomeEnum.FOO must refer to an object with a "value" key representing ' +
'an internal value but got: 10.',
Expand All @@ -1114,12 +1098,10 @@ describe('Type System: Enum types must be well defined', () => {
const config = {
name: 'SomeEnum',
values: {
FOO: {
isDeprecated: true,
},
// $DisableFlowOnNegativeTest
FOO: { isDeprecated: true },
},
};
// $DisableFlowOnNegativeTest
expect(() => new GraphQLEnumType(config)).to.throw(
'SomeEnum.FOO should provide "deprecationReason" instead ' +
'of "isDeprecated".',
Expand Down
4 changes: 2 additions & 2 deletions src/type/__tests__/directive-test.js
Expand Up @@ -78,10 +78,10 @@ describe('Type System: Directive', () => {
it('reject directive incorrectly typed args', () => {
expect(
() =>
// $DisableFlowOnNegativeTest
new GraphQLDirective({
name: 'Foo',
locations: ['Query'],
locations: ['QUERY'],
// $DisableFlowOnNegativeTest
args: [],
}),
).to.throw('@Foo args must be an object with argument names as keys.');
Expand Down
38 changes: 15 additions & 23 deletions src/type/__tests__/schema-test.js
Expand Up @@ -61,12 +61,7 @@ const Schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: {
getObject: {
type: InterfaceType,
resolve() {
return {};
},
},
getObject: { type: InterfaceType },
},
}),
directives: [Directive],
Expand Down Expand Up @@ -176,24 +171,21 @@ describe('Type System: Schema', () => {
});

it('does not check the configuration for mistakes', () => {
expect(() => {
const config = () => null;
config.assumeValid = true;
// $DisableFlowOnNegativeTest
return new GraphQLSchema(config);
}).to.not.throw();

expect(() => {
return new GraphQLSchema({
assumeValid: true,
// $DisableFlowOnNegativeTest
types: {},
// $DisableFlowOnNegativeTest
directives: { reduce: () => [] },
const config = () => null;
config.assumeValid = true;
// $DisableFlowOnNegativeTest
expect(() => new GraphQLSchema(config)).to.not.throw();

expect(
() =>
// $DisableFlowOnNegativeTest
allowedLegacyNames: {},
});
}).to.not.throw();
new GraphQLSchema({
assumeValid: true,
types: {},
directives: { reduce: () => [] },
allowedLegacyNames: {},
}),
).to.not.throw();
});
});
});
Expand Down
10 changes: 6 additions & 4 deletions src/type/__tests__/validation-test.js
Expand Up @@ -687,10 +687,12 @@ describe('Type System: Union types must be valid', () => {
SomeInputObjectType,
];
for (const memberType of badUnionMemberTypes) {
const badSchema = schemaWithFieldType(
const badUnion = new GraphQLUnionType({
name: 'BadUnion',
// $DisableFlowOnNegativeTest
new GraphQLUnionType({ name: 'BadUnion', types: [memberType] }),
);
types: [memberType],
});
const badSchema = schemaWithFieldType(badUnion);
expect(validateSchema(badSchema)).to.deep.equal([
{
message:
Expand Down Expand Up @@ -944,9 +946,9 @@ describe('Type System: Object fields must have output types', () => {
describe('Type System: Objects can only implement unique interfaces', () => {
it('rejects an Object implementing a non-type values', () => {
const schema = new GraphQLSchema({
// $DisableFlowOnNegativeTest
query: new GraphQLObjectType({
name: 'BadObject',
// $DisableFlowOnNegativeTest
interfaces: [undefined],
fields: { f: { type: GraphQLString } },
}),
Expand Down

0 comments on commit 6876587

Please sign in to comment.