Skip to content

Commit 6876587

Browse files
Move $DisableFlowOnNegativeTest to more precise locations (#1664)
1 parent 8d7a5fd commit 6876587

File tree

4 files changed

+56
-80
lines changed

4 files changed

+56
-80
lines changed

src/type/__tests__/definition-test.js

Lines changed: 33 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -474,10 +474,10 @@ describe('Field config must be object', () => {
474474
});
475475

476476
it('rejects an Object type field with undefined config', () => {
477-
// $DisableFlowOnNegativeTest
478477
const objType = new GraphQLObjectType({
479478
name: 'SomeObject',
480479
fields: {
480+
// $DisableFlowOnNegativeTest
481481
f: undefined,
482482
},
483483
});
@@ -487,9 +487,9 @@ describe('Field config must be object', () => {
487487
});
488488

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

501501
it('rejects an Object type with a field function that returns incorrect type', () => {
502-
// $DisableFlowOnNegativeTest
503502
const objType = new GraphQLObjectType({
504503
name: 'SomeObject',
505504
fields() {
505+
// $DisableFlowOnNegativeTest
506506
return [{ field: GraphQLString }];
507507
},
508508
});
@@ -530,12 +530,12 @@ describe('Field arg config must be object', () => {
530530
});
531531

532532
it('rejects an Object type with incorrectly typed field args', () => {
533-
// $DisableFlowOnNegativeTest
534533
const objType = new GraphQLObjectType({
535534
name: 'SomeObject',
536535
fields: {
537536
badField: {
538537
type: GraphQLString,
538+
// $DisableFlowOnNegativeTest
539539
args: [{ badArg: GraphQLString }],
540540
},
541541
},
@@ -547,14 +547,11 @@ describe('Field arg config must be object', () => {
547547

548548
it('does not allow isDeprecated instead of deprecationReason on field', () => {
549549
expect(() => {
550-
// $DisableFlowOnNegativeTest
551550
const OldObject = new GraphQLObjectType({
552551
name: 'OldObject',
553552
fields: {
554-
field: {
555-
type: GraphQLString,
556-
isDeprecated: true,
557-
},
553+
// $DisableFlowOnNegativeTest
554+
field: { type: GraphQLString, isDeprecated: true },
558555
},
559556
});
560557

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

588585
it('rejects an Object type with incorrectly typed interfaces', () => {
589-
// $DisableFlowOnNegativeTest
590586
const objType = new GraphQLObjectType({
591587
name: 'SomeObject',
588+
fields: {},
589+
// $DisableFlowOnNegativeTest
592590
interfaces: {},
593-
fields: { f: { type: GraphQLString } },
594591
});
595592
expect(() => objType.getInterfaces()).to.throw(
596593
'SomeObject interfaces must be an Array or a function which returns an Array.',
597594
);
598595
});
599596

600597
it('rejects an Object type with interfaces as a function returning an incorrect type', () => {
601-
// $DisableFlowOnNegativeTest
602598
const objType = new GraphQLObjectType({
603599
name: 'SomeObject',
600+
fields: {},
601+
// $DisableFlowOnNegativeTest
604602
interfaces() {
605603
return {};
606604
},
607-
fields: { f: { type: GraphQLString } },
608605
});
609606
expect(() => objType.getInterfaces()).to.throw(
610607
'SomeObject interfaces must be an Array or a function which returns an Array.',
@@ -712,11 +709,11 @@ describe('Type System: Interface types must be resolvable', () => {
712709
it('rejects an Interface type with an incorrect type for resolveType', () => {
713710
expect(
714711
() =>
715-
// $DisableFlowOnNegativeTest
716712
new GraphQLInterfaceType({
717713
name: 'AnotherInterface',
714+
fields: {},
715+
// $DisableFlowOnNegativeTest
718716
resolveType: {},
719-
fields: { f: { type: GraphQLString } },
720717
}),
721718
).to.throw(
722719
'AnotherInterface must provide "resolveType" as a function, but got: {}.',
@@ -766,11 +763,11 @@ describe('Type System: Union types must be resolvable', () => {
766763
it('rejects an Interface type with an incorrect type for resolveType', () => {
767764
expect(() =>
768765
schemaWithFieldType(
769-
// $DisableFlowOnNegativeTest
770766
new GraphQLUnionType({
771767
name: 'SomeUnion',
768+
types: [],
769+
// $DisableFlowOnNegativeTest
772770
resolveType: {},
773-
types: [ObjectWithIsTypeOf],
774771
}),
775772
),
776773
).to.throw(
@@ -792,7 +789,6 @@ describe('Type System: Scalar types must be serializable', () => {
792789
});
793790

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

810806
it('rejects a Scalar type defining serialize with an incorrect type', () => {
811-
// $DisableFlowOnNegativeTest
812807
expect(() =>
813808
schemaWithFieldType(
814-
// $DisableFlowOnNegativeTest
815809
new GraphQLScalarType({
816810
name: 'SomeScalar',
811+
// $DisableFlowOnNegativeTest
817812
serialize: {},
818813
}),
819814
),
@@ -868,11 +863,12 @@ describe('Type System: Scalar types must be serializable', () => {
868863
it('rejects a Scalar type defining parseValue and parseLiteral with an incorrect type', () => {
869864
expect(() =>
870865
schemaWithFieldType(
871-
// $DisableFlowOnNegativeTest
872866
new GraphQLScalarType({
873867
name: 'SomeScalar',
874868
serialize: () => null,
869+
// $DisableFlowOnNegativeTest
875870
parseValue: {},
871+
// $DisableFlowOnNegativeTest
876872
parseLiteral: {},
877873
}),
878874
),
@@ -897,11 +893,11 @@ describe('Type System: Object types must be assertable', () => {
897893
it('rejects an Object type with an incorrect type for isTypeOf', () => {
898894
expect(() => {
899895
schemaWithFieldType(
900-
// $DisableFlowOnNegativeTest
901896
new GraphQLObjectType({
902897
name: 'AnotherObject',
898+
fields: {},
899+
// $DisableFlowOnNegativeTest
903900
isTypeOf: {},
904-
fields: { f: { type: GraphQLString } },
905901
}),
906902
);
907903
}).to.throw(
@@ -947,12 +943,10 @@ describe('Type System: Union types must be array', () => {
947943
it('rejects a Union type with incorrectly typed types', () => {
948944
expect(() =>
949945
schemaWithFieldType(
950-
// $DisableFlowOnNegativeTest
951946
new GraphQLUnionType({
952947
name: 'SomeUnion',
953-
types: {
954-
ObjectType,
955-
},
948+
// $DisableFlowOnNegativeTest
949+
types: { ObjectType },
956950
}),
957951
),
958952
).to.throw(
@@ -986,9 +980,9 @@ describe('Type System: Input Objects must have fields', () => {
986980
});
987981

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

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

10151007
describe('Type System: Input Object fields must not have resolvers', () => {
10161008
it('rejects an Input Object type with resolvers', () => {
1017-
// $DisableFlowOnNegativeTest
10181009
const inputObjType = new GraphQLInputObjectType({
10191010
name: 'SomeInputObject',
10201011
fields: {
1021-
f: {
1022-
type: GraphQLString,
1023-
resolve: () => {
1024-
return 0;
1025-
},
1026-
},
1012+
// $DisableFlowOnNegativeTest
1013+
f: { type: GraphQLString, resolve: () => 0 },
10271014
},
10281015
});
10291016
expect(() => inputObjType.getFields()).to.throw(
@@ -1033,14 +1020,11 @@ describe('Type System: Input Object fields must not have resolvers', () => {
10331020
});
10341021

10351022
it('rejects an Input Object type with resolver constant', () => {
1036-
// $DisableFlowOnNegativeTest
10371023
const inputObjType = new GraphQLInputObjectType({
10381024
name: 'SomeInputObject',
10391025
fields: {
1040-
f: {
1041-
type: GraphQLString,
1042-
resolve: {},
1043-
},
1026+
// $DisableFlowOnNegativeTest
1027+
f: { type: GraphQLString, resolve: {} },
10441028
},
10451029
});
10461030
expect(() => inputObjType.getFields()).to.throw(
@@ -1078,9 +1062,9 @@ describe('Type System: Enum types must be well defined', () => {
10781062
it('rejects an Enum type with incorrectly typed values', () => {
10791063
const config = {
10801064
name: 'SomeEnum',
1065+
// $DisableFlowOnNegativeTest
10811066
values: [{ FOO: 10 }],
10821067
};
1083-
// $DisableFlowOnNegativeTest
10841068
expect(() => new GraphQLEnumType(config)).to.throw(
10851069
'SomeEnum values must be an object with value names as keys.',
10861070
);
@@ -1089,9 +1073,9 @@ describe('Type System: Enum types must be well defined', () => {
10891073
it('rejects an Enum type with missing value definition', () => {
10901074
const config = {
10911075
name: 'SomeEnum',
1076+
// $DisableFlowOnNegativeTest
10921077
values: { FOO: null },
10931078
};
1094-
// $DisableFlowOnNegativeTest
10951079
expect(() => new GraphQLEnumType(config)).to.throw(
10961080
'SomeEnum.FOO must refer to an object with a "value" key representing ' +
10971081
'an internal value but got: null.',
@@ -1101,9 +1085,9 @@ describe('Type System: Enum types must be well defined', () => {
11011085
it('rejects an Enum type with incorrectly typed value definition', () => {
11021086
const config = {
11031087
name: 'SomeEnum',
1088+
// $DisableFlowOnNegativeTest
11041089
values: { FOO: 10 },
11051090
};
1106-
// $DisableFlowOnNegativeTest
11071091
expect(() => new GraphQLEnumType(config)).to.throw(
11081092
'SomeEnum.FOO must refer to an object with a "value" key representing ' +
11091093
'an internal value but got: 10.',
@@ -1114,12 +1098,10 @@ describe('Type System: Enum types must be well defined', () => {
11141098
const config = {
11151099
name: 'SomeEnum',
11161100
values: {
1117-
FOO: {
1118-
isDeprecated: true,
1119-
},
1101+
// $DisableFlowOnNegativeTest
1102+
FOO: { isDeprecated: true },
11201103
},
11211104
};
1122-
// $DisableFlowOnNegativeTest
11231105
expect(() => new GraphQLEnumType(config)).to.throw(
11241106
'SomeEnum.FOO should provide "deprecationReason" instead ' +
11251107
'of "isDeprecated".',

src/type/__tests__/directive-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ describe('Type System: Directive', () => {
7878
it('reject directive incorrectly typed args', () => {
7979
expect(
8080
() =>
81-
// $DisableFlowOnNegativeTest
8281
new GraphQLDirective({
8382
name: 'Foo',
84-
locations: ['Query'],
83+
locations: ['QUERY'],
84+
// $DisableFlowOnNegativeTest
8585
args: [],
8686
}),
8787
).to.throw('@Foo args must be an object with argument names as keys.');

src/type/__tests__/schema-test.js

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,7 @@ const Schema = new GraphQLSchema({
6161
query: new GraphQLObjectType({
6262
name: 'Query',
6363
fields: {
64-
getObject: {
65-
type: InterfaceType,
66-
resolve() {
67-
return {};
68-
},
69-
},
64+
getObject: { type: InterfaceType },
7065
},
7166
}),
7267
directives: [Directive],
@@ -176,24 +171,21 @@ describe('Type System: Schema', () => {
176171
});
177172

178173
it('does not check the configuration for mistakes', () => {
179-
expect(() => {
180-
const config = () => null;
181-
config.assumeValid = true;
182-
// $DisableFlowOnNegativeTest
183-
return new GraphQLSchema(config);
184-
}).to.not.throw();
185-
186-
expect(() => {
187-
return new GraphQLSchema({
188-
assumeValid: true,
189-
// $DisableFlowOnNegativeTest
190-
types: {},
191-
// $DisableFlowOnNegativeTest
192-
directives: { reduce: () => [] },
174+
const config = () => null;
175+
config.assumeValid = true;
176+
// $DisableFlowOnNegativeTest
177+
expect(() => new GraphQLSchema(config)).to.not.throw();
178+
179+
expect(
180+
() =>
193181
// $DisableFlowOnNegativeTest
194-
allowedLegacyNames: {},
195-
});
196-
}).to.not.throw();
182+
new GraphQLSchema({
183+
assumeValid: true,
184+
types: {},
185+
directives: { reduce: () => [] },
186+
allowedLegacyNames: {},
187+
}),
188+
).to.not.throw();
197189
});
198190
});
199191
});

src/type/__tests__/validation-test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -687,10 +687,12 @@ describe('Type System: Union types must be valid', () => {
687687
SomeInputObjectType,
688688
];
689689
for (const memberType of badUnionMemberTypes) {
690-
const badSchema = schemaWithFieldType(
690+
const badUnion = new GraphQLUnionType({
691+
name: 'BadUnion',
691692
// $DisableFlowOnNegativeTest
692-
new GraphQLUnionType({ name: 'BadUnion', types: [memberType] }),
693-
);
693+
types: [memberType],
694+
});
695+
const badSchema = schemaWithFieldType(badUnion);
694696
expect(validateSchema(badSchema)).to.deep.equal([
695697
{
696698
message:
@@ -944,9 +946,9 @@ describe('Type System: Object fields must have output types', () => {
944946
describe('Type System: Objects can only implement unique interfaces', () => {
945947
it('rejects an Object implementing a non-type values', () => {
946948
const schema = new GraphQLSchema({
947-
// $DisableFlowOnNegativeTest
948949
query: new GraphQLObjectType({
949950
name: 'BadObject',
951+
// $DisableFlowOnNegativeTest
950952
interfaces: [undefined],
951953
fields: { f: { type: GraphQLString } },
952954
}),

0 commit comments

Comments
 (0)