@@ -16,6 +16,10 @@ import type {
16
16
GraphQLNamedType ,
17
17
GraphQLInputType ,
18
18
GraphQLOutputType ,
19
+ GraphQLFieldConfig ,
20
+ GraphQLArgumentConfig ,
21
+ GraphQLInputFieldConfig ,
22
+ GraphQLEnumValueConfigMap ,
19
23
} from '../definition' ;
20
24
import { GraphQLSchema } from '../schema' ;
21
25
import { GraphQLString } from '../scalars' ;
@@ -103,13 +107,12 @@ const notInputTypes: Array<GraphQLOutputType> = [
103
107
...withModifiers(SomeInterfaceType),
104
108
];
105
109
106
- function schemaWithFieldType(type) {
110
+ function schemaWithFieldType(type: GraphQLOutputType): GraphQLSchema {
107
111
return new GraphQLSchema ( {
108
112
query : new GraphQLObjectType ( {
109
113
name : 'Query' ,
110
114
fields : { f : { type } } ,
111
115
} ) ,
112
- types : [ type ] ,
113
116
} ) ;
114
117
}
115
118
@@ -516,18 +519,20 @@ describe('Type System: Fields args must be properly named', () => {
516
519
} ) ;
517
520
518
521
it ( 'rejects field arg with invalid names' , ( ) => {
519
- const QueryType = new GraphQLObjectType ( {
520
- name : 'SomeObject' ,
521
- fields : {
522
- badField : {
523
- type : GraphQLString ,
524
- args : {
525
- 'bad-name-with-dashes' : { type : GraphQLString } ,
522
+ const schema = schemaWithFieldType (
523
+ new GraphQLObjectType ( {
524
+ name : 'SomeObject' ,
525
+ fields : {
526
+ badField : {
527
+ type : GraphQLString ,
528
+ args : {
529
+ 'bad-name-with-dashes' : { type : GraphQLString } ,
530
+ } ,
526
531
} ,
527
532
} ,
528
- } ,
529
- } ) ;
530
- const schema = new GraphQLSchema ( { query : QueryType } ) ;
533
+ } ) ,
534
+ ) ;
535
+
531
536
expect ( validateSchema ( schema ) ) . to . deep . equal ( [
532
537
{
533
538
message :
@@ -928,7 +933,7 @@ describe('Type System: Enum types must be well defined', () => {
928
933
} ) ;
929
934
930
935
it ( 'rejects an Enum type with incorrectly named values' , ( ) => {
931
- function schemaWithEnum ( values ) {
936
+ function schemaWithEnum ( values : GraphQLEnumValueConfigMap ) : GraphQLSchema {
932
937
return schemaWithFieldType (
933
938
new GraphQLEnumType ( {
934
939
name : 'SomeEnum' ,
@@ -979,11 +984,13 @@ describe('Type System: Enum types must be well defined', () => {
979
984
} );
980
985
981
986
describe('Type System: Object fields must have output types', () => {
982
- function schemaWithObjectFieldOfType ( fieldType : GraphQLOutputType ) {
987
+ function schemaWithObjectField (
988
+ fieldConfig : GraphQLFieldConfig < mixed , mixed > ,
989
+ ) : GraphQLSchema {
983
990
const BadObjectType = new GraphQLObjectType ( {
984
991
name : 'BadObject' ,
985
992
fields : {
986
- badField : { type : fieldType } ,
993
+ badField : fieldConfig ,
987
994
} ,
988
995
} ) ;
989
996
@@ -1001,14 +1008,14 @@ describe('Type System: Object fields must have output types', () => {
1001
1008
for ( const type of outputTypes ) {
1002
1009
const typeName = inspect ( type ) ;
1003
1010
it ( `accepts an output type as an Object field type: ${ typeName } ` , ( ) => {
1004
- const schema = schemaWithObjectFieldOfType ( type ) ;
1011
+ const schema = schemaWithObjectField ( { type } ) ;
1005
1012
expect ( validateSchema ( schema ) ) . to . deep . equal ( [ ] ) ;
1006
1013
} ) ;
1007
1014
}
1008
1015
1009
1016
it('rejects an empty Object field type', () => {
1010
1017
// $FlowExpectedError
1011
- const schema = schemaWithObjectFieldOfType ( undefined ) ;
1018
+ const schema = schemaWithObjectField ( { type : undefined } ) ;
1012
1019
expect ( validateSchema ( schema ) ) . to . deep . equal ( [
1013
1020
{
1014
1021
message :
@@ -1021,7 +1028,7 @@ describe('Type System: Object fields must have output types', () => {
1021
1028
const typeStr = inspect ( type ) ;
1022
1029
it ( `rejects a non-output type as an Object field type: ${ typeStr } ` , ( ) => {
1023
1030
// $FlowExpectedError
1024
- const schema = schemaWithObjectFieldOfType ( type ) ;
1031
+ const schema = schemaWithObjectField ( { type } ) ;
1025
1032
expect ( validateSchema ( schema ) ) . to . deep . equal ( [
1026
1033
{
1027
1034
message : `The type of BadObject.badField must be Output Type but got: ${ typeStr } .` ,
@@ -1032,7 +1039,7 @@ describe('Type System: Object fields must have output types', () => {
1032
1039
1033
1040
it('rejects a non-type value as an Object field type', () => {
1034
1041
// $FlowExpectedError
1035
- const schema = schemaWithObjectFieldOfType ( Number ) ;
1042
+ const schema = schemaWithObjectField ( { type : Number } ) ;
1036
1043
expect ( validateSchema ( schema ) ) . to . deep . equal ( [
1037
1044
{
1038
1045
message :
@@ -1292,20 +1299,20 @@ describe('Type System: Interface extensions should be valid', () => {
1292
1299
} ) ;
1293
1300
1294
1301
describe ( 'Type System: Interface fields must have output types' , ( ) => {
1295
- function schemaWithInterfaceFieldOfType ( fieldType : GraphQLOutputType ) {
1302
+ function schemaWithInterfaceField (
1303
+ fieldConfig : GraphQLFieldConfig < mixed , mixed > ,
1304
+ ) : GraphQLSchema {
1305
+ const fields = { badField : fieldConfig } ;
1306
+
1296
1307
const BadInterfaceType = new GraphQLInterfaceType ( {
1297
1308
name : 'BadInterface' ,
1298
- fields : {
1299
- badField : { type : fieldType } ,
1300
- } ,
1309
+ fields,
1301
1310
} ) ;
1302
1311
1303
1312
const BadImplementingType = new GraphQLObjectType ( {
1304
1313
name : 'BadImplementing' ,
1305
1314
interfaces : [ BadInterfaceType ] ,
1306
- fields : {
1307
- badField : { type : fieldType } ,
1308
- } ,
1315
+ fields,
1309
1316
} ) ;
1310
1317
1311
1318
return new GraphQLSchema ( {
@@ -1322,14 +1329,14 @@ describe('Type System: Interface fields must have output types', () => {
1322
1329
for ( const type of outputTypes ) {
1323
1330
const typeName = inspect ( type ) ;
1324
1331
it ( `accepts an output type as an Interface field type: ${ typeName } ` , ( ) => {
1325
- const schema = schemaWithInterfaceFieldOfType ( type ) ;
1332
+ const schema = schemaWithInterfaceField ( { type } ) ;
1326
1333
expect ( validateSchema ( schema ) ) . to . deep . equal ( [ ] ) ;
1327
1334
} ) ;
1328
1335
}
1329
1336
1330
1337
it ( 'rejects an empty Interface field type' , ( ) => {
1331
1338
// $FlowExpectedError
1332
- const schema = schemaWithInterfaceFieldOfType ( undefined ) ;
1339
+ const schema = schemaWithInterfaceField ( { type : undefined } ) ;
1333
1340
expect ( validateSchema ( schema ) ) . to . deep . equal ( [
1334
1341
{
1335
1342
message :
@@ -1346,7 +1353,7 @@ describe('Type System: Interface fields must have output types', () => {
1346
1353
const typeStr = inspect ( type ) ;
1347
1354
it ( `rejects a non-output type as an Interface field type: ${ typeStr } ` , ( ) => {
1348
1355
// $FlowExpectedError
1349
- const schema = schemaWithInterfaceFieldOfType ( type ) ;
1356
+ const schema = schemaWithInterfaceField ( { type } ) ;
1350
1357
expect ( validateSchema ( schema ) ) . to . deep . equal ( [
1351
1358
{
1352
1359
message : `The type of BadImplementing.badField must be Output Type but got: ${ typeStr } .` ,
@@ -1360,7 +1367,7 @@ describe('Type System: Interface fields must have output types', () => {
1360
1367
1361
1368
it ( 'rejects a non-type value as an Interface field type' , ( ) => {
1362
1369
// $FlowExpectedError
1363
- const schema = schemaWithInterfaceFieldOfType ( Number ) ;
1370
+ const schema = schemaWithInterfaceField ( { type : Number } ) ;
1364
1371
expect ( validateSchema ( schema ) ) . to . deep . equal ( [
1365
1372
{
1366
1373
message :
@@ -1423,14 +1430,14 @@ describe('Type System: Interface fields must have output types', () => {
1423
1430
} ) ;
1424
1431
1425
1432
describe ( 'Type System: Arguments must have input types' , ( ) => {
1426
- function schemaWithArgOfType ( argType : GraphQLInputType ) {
1433
+ function schemaWithArg ( argConfig : GraphQLArgumentConfig ) : GraphQLSchema {
1427
1434
const BadObjectType = new GraphQLObjectType ( {
1428
1435
name : 'BadObject' ,
1429
1436
fields : {
1430
1437
badField : {
1431
1438
type : GraphQLString ,
1432
1439
args : {
1433
- badArg : { type : argType } ,
1440
+ badArg : argConfig ,
1434
1441
} ,
1435
1442
} ,
1436
1443
} ,
@@ -1447,7 +1454,7 @@ describe('Type System: Arguments must have input types', () => {
1447
1454
new GraphQLDirective ( {
1448
1455
name : 'BadDirective' ,
1449
1456
args : {
1450
- badArg : { type : argType } ,
1457
+ badArg : argConfig ,
1451
1458
} ,
1452
1459
locations : [ 'QUERY' ] ,
1453
1460
} ) ,
@@ -1458,14 +1465,14 @@ describe('Type System: Arguments must have input types', () => {
1458
1465
for ( const type of inputTypes ) {
1459
1466
const typeName = inspect ( type ) ;
1460
1467
it ( `accepts an input type as a field arg type: ${ typeName } ` , ( ) => {
1461
- const schema = schemaWithArgOfType ( type ) ;
1468
+ const schema = schemaWithArg ( { type } ) ;
1462
1469
expect ( validateSchema ( schema ) ) . to . deep . equal ( [ ] ) ;
1463
1470
} ) ;
1464
1471
}
1465
1472
1466
1473
it ( 'rejects an empty field arg type' , ( ) => {
1467
1474
// $FlowExpectedError
1468
- const schema = schemaWithArgOfType ( undefined ) ;
1475
+ const schema = schemaWithArg ( { type : undefined } ) ;
1469
1476
expect ( validateSchema ( schema ) ) . to . deep . equal ( [
1470
1477
{
1471
1478
message :
@@ -1482,7 +1489,7 @@ describe('Type System: Arguments must have input types', () => {
1482
1489
const typeStr = inspect ( type ) ;
1483
1490
it ( `rejects a non-input type as a field arg type: ${ typeStr } ` , ( ) => {
1484
1491
// $FlowExpectedError
1485
- const schema = schemaWithArgOfType ( type ) ;
1492
+ const schema = schemaWithArg ( { type } ) ;
1486
1493
expect ( validateSchema ( schema ) ) . to . deep . equal ( [
1487
1494
{
1488
1495
message : `The type of @BadDirective(badArg:) must be Input Type but got: ${ typeStr } .` ,
@@ -1496,7 +1503,7 @@ describe('Type System: Arguments must have input types', () => {
1496
1503
1497
1504
it ( 'rejects a non-type value as a field arg type' , ( ) => {
1498
1505
// $FlowExpectedError
1499
- const schema = schemaWithArgOfType ( Number ) ;
1506
+ const schema = schemaWithArg ( { type : Number } ) ;
1500
1507
expect ( validateSchema ( schema ) ) . to . deep . equal ( [
1501
1508
{
1502
1509
message :
@@ -1533,11 +1540,13 @@ describe('Type System: Arguments must have input types', () => {
1533
1540
} ) ;
1534
1541
1535
1542
describe ( 'Type System: Input Object fields must have input types' , ( ) => {
1536
- function schemaWithInputFieldOfType ( inputFieldType : GraphQLInputType ) {
1543
+ function schemaWithInputField (
1544
+ inputFieldConfig : GraphQLInputFieldConfig ,
1545
+ ) : GraphQLSchema {
1537
1546
const BadInputObjectType = new GraphQLInputObjectType ( {
1538
1547
name : 'BadInputObject' ,
1539
1548
fields : {
1540
- badField : { type : inputFieldType } ,
1549
+ badField : inputFieldConfig ,
1541
1550
} ,
1542
1551
} ) ;
1543
1552
@@ -1559,14 +1568,14 @@ describe('Type System: Input Object fields must have input types', () => {
1559
1568
for ( const type of inputTypes ) {
1560
1569
const typeName = inspect ( type ) ;
1561
1570
it ( `accepts an input type as an input field type: ${ typeName } ` , ( ) => {
1562
- const schema = schemaWithInputFieldOfType ( type ) ;
1571
+ const schema = schemaWithInputField ( { type } ) ;
1563
1572
expect ( validateSchema ( schema ) ) . to . deep . equal ( [ ] ) ;
1564
1573
} ) ;
1565
1574
}
1566
1575
1567
1576
it ( 'rejects an empty input field type' , ( ) => {
1568
1577
// $FlowExpectedError
1569
- const schema = schemaWithInputFieldOfType ( undefined ) ;
1578
+ const schema = schemaWithInputField ( { type : undefined } ) ;
1570
1579
expect ( validateSchema ( schema ) ) . to . deep . equal ( [
1571
1580
{
1572
1581
message :
@@ -1579,7 +1588,7 @@ describe('Type System: Input Object fields must have input types', () => {
1579
1588
const typeStr = inspect ( type ) ;
1580
1589
it ( `rejects a non-input type as an input field type: ${ typeStr } ` , ( ) => {
1581
1590
// $FlowExpectedError
1582
- const schema = schemaWithInputFieldOfType ( type ) ;
1591
+ const schema = schemaWithInputField ( { type } ) ;
1583
1592
expect ( validateSchema ( schema ) ) . to . deep . equal ( [
1584
1593
{
1585
1594
message : `The type of BadInputObject.badField must be Input Type but got: ${ typeStr } .` ,
@@ -1590,7 +1599,7 @@ describe('Type System: Input Object fields must have input types', () => {
1590
1599
1591
1600
it ( 'rejects a non-type value as an input field type' , ( ) => {
1592
1601
// $FlowExpectedError
1593
- const schema = schemaWithInputFieldOfType ( Number ) ;
1602
+ const schema = schemaWithInputField ( { type : Number } ) ;
1594
1603
expect ( validateSchema ( schema ) ) . to . deep . equal ( [
1595
1604
{
1596
1605
message :
0 commit comments