@@ -16,16 +16,12 @@ import {
16
16
GraphQLNonNull ,
17
17
GraphQLObjectType ,
18
18
GraphQLScalarType ,
19
- GraphQLSemanticNonNull ,
20
- GraphQLSemanticNullable ,
21
19
GraphQLUnionType ,
22
20
} from '../../type/definition' ;
23
21
import { GraphQLBoolean , GraphQLInt , GraphQLString } from '../../type/scalars' ;
24
22
import { GraphQLSchema } from '../../type/schema' ;
25
23
26
24
import { execute , executeSync } from '../execute' ;
27
- import { GraphQLError } from '../../error' ;
28
- import { ExecutableDefinitionNode , FieldNode , SelectionSetNode } from '../../language' ;
29
25
30
26
describe ( 'Execute: Handles basic execution tasks' , ( ) => {
31
27
it ( 'throws if no document is provided' , ( ) => {
@@ -1328,198 +1324,3 @@ describe('Execute: Handles basic execution tasks', () => {
1328
1324
} ) ;
1329
1325
} ) ;
1330
1326
1331
- describe ( 'Execute: Handles Semantic Nullability' , ( ) => {
1332
- const DeepDataType = new GraphQLObjectType ( {
1333
- name : 'DeepDataType' ,
1334
- fields : {
1335
- f : { type : new GraphQLNonNull ( GraphQLString ) }
1336
- } ,
1337
- } ) ;
1338
-
1339
- const DataType : GraphQLObjectType = new GraphQLObjectType ( {
1340
- name : 'DataType' ,
1341
- fields : ( ) => ( {
1342
- a : { type : new GraphQLSemanticNullable ( GraphQLString ) } ,
1343
- b : { type : new GraphQLSemanticNonNull ( GraphQLString ) } ,
1344
- c : { type : new GraphQLNonNull ( GraphQLString ) } ,
1345
- d : { type : new GraphQLSemanticNonNull ( DeepDataType ) }
1346
- } ) ,
1347
- } ) ;
1348
-
1349
- it ( 'SemanticNonNull throws error on null without error' , async ( ) => {
1350
- const data = {
1351
- a : ( ) => 'Apple' ,
1352
- b : ( ) => null ,
1353
- c : ( ) => 'Cookie'
1354
- } ;
1355
-
1356
- const document = parse ( `
1357
- query {
1358
- b
1359
- }
1360
- ` ) ;
1361
-
1362
- const result = await execute ( {
1363
- schema : new GraphQLSchema ( { query : DataType } ) ,
1364
- document,
1365
- rootValue : data ,
1366
- } ) ;
1367
-
1368
- let executable = document . definitions ?. values ( ) . next ( ) . value as ExecutableDefinitionNode ;
1369
- let selectionSet = executable . selectionSet . selections . values ( ) . next ( ) . value ;
1370
-
1371
- expect ( result ) . to . deep . equal ( {
1372
- data : {
1373
- b : null
1374
- } ,
1375
- errors : [
1376
- new GraphQLError (
1377
- 'Cannot return null for semantic-non-nullable field DataType.b.' ,
1378
- {
1379
- nodes : selectionSet ,
1380
- path : [ 'b' ]
1381
- }
1382
- )
1383
- ]
1384
- } ) ;
1385
- } ) ;
1386
-
1387
- it ( 'SemanticNonNull succeeds on null with error' , async ( ) => {
1388
- const data = {
1389
- a : ( ) => 'Apple' ,
1390
- b : ( ) => { throw new Error (
1391
- `Something went wrong` ,
1392
- ) ; } ,
1393
- c : ( ) => 'Cookie'
1394
- } ;
1395
-
1396
- const document = parse ( `
1397
- query {
1398
- b
1399
- }
1400
- ` ) ;
1401
-
1402
- let executable = document . definitions ?. values ( ) . next ( ) . value as ExecutableDefinitionNode ;
1403
- let selectionSet = executable . selectionSet . selections . values ( ) . next ( ) . value ;
1404
-
1405
- const result = await execute ( {
1406
- schema : new GraphQLSchema ( { query : DataType } ) ,
1407
- document,
1408
- rootValue : data ,
1409
- } ) ;
1410
-
1411
- expect ( result ) . to . deep . equal ( {
1412
- data : {
1413
- b : null
1414
- } ,
1415
- errors : [
1416
- new GraphQLError (
1417
- 'Something went wrong' ,
1418
- {
1419
- nodes : selectionSet ,
1420
- path : [ 'b' ]
1421
- }
1422
- )
1423
- ]
1424
- } ) ;
1425
- } ) ;
1426
-
1427
- it ( 'SemanticNonNull halts null propagation' , async ( ) => {
1428
- const deepData = {
1429
- f : ( ) => null
1430
- } ;
1431
-
1432
- const data = {
1433
- a : ( ) => 'Apple' ,
1434
- b : ( ) => null ,
1435
- c : ( ) => 'Cookie' ,
1436
- d : ( ) => deepData
1437
- } ;
1438
-
1439
-
1440
- const document = parse ( `
1441
- query {
1442
- d {
1443
- f
1444
- }
1445
- }
1446
- ` ) ;
1447
-
1448
- const result = await execute ( {
1449
- schema : new GraphQLSchema ( { query : DataType } ) ,
1450
- document,
1451
- rootValue : data ,
1452
- } ) ;
1453
-
1454
- let executable = document . definitions ?. values ( ) . next ( ) . value as ExecutableDefinitionNode ;
1455
- let dSelectionSet = executable . selectionSet . selections . values ( ) . next ( ) . value as FieldNode ;
1456
- let fSelectionSet = dSelectionSet . selectionSet ?. selections . values ( ) . next ( ) . value ;
1457
-
1458
- expect ( result ) . to . deep . equal ( {
1459
- data : {
1460
- d : null
1461
- } ,
1462
- errors : [
1463
- new GraphQLError (
1464
- 'Cannot return null for non-nullable field DeepDataType.f.' ,
1465
- {
1466
- nodes : fSelectionSet ,
1467
- path : [ 'd' , 'f' ]
1468
- }
1469
- )
1470
- ]
1471
- } ) ;
1472
- } ) ;
1473
-
1474
- it ( 'SemanticNullable allows null values' , async ( ) => {
1475
- const data = {
1476
- a : ( ) => null ,
1477
- b : ( ) => null ,
1478
- c : ( ) => 'Cookie'
1479
- } ;
1480
-
1481
- const document = parse ( `
1482
- query {
1483
- a
1484
- }
1485
- ` ) ;
1486
-
1487
- const result = await execute ( {
1488
- schema : new GraphQLSchema ( { query : DataType } ) ,
1489
- document,
1490
- rootValue : data ,
1491
- } ) ;
1492
-
1493
- expect ( result ) . to . deep . equal ( {
1494
- data : {
1495
- a : null
1496
- }
1497
- } ) ;
1498
- } ) ;
1499
-
1500
- it ( 'SemanticNullable allows non-null values' , async ( ) => {
1501
- const data = {
1502
- a : ( ) => 'Apple' ,
1503
- b : ( ) => null ,
1504
- c : ( ) => 'Cookie'
1505
- } ;
1506
-
1507
- const document = parse ( `
1508
- query {
1509
- a
1510
- }
1511
- ` ) ;
1512
-
1513
- const result = await execute ( {
1514
- schema : new GraphQLSchema ( { query : DataType } ) ,
1515
- document,
1516
- rootValue : data ,
1517
- } ) ;
1518
-
1519
- expect ( result ) . to . deep . equal ( {
1520
- data : {
1521
- a : 'Apple'
1522
- }
1523
- } ) ;
1524
- } ) ;
1525
- } ) ;
0 commit comments