|
3 | 3 | import { expect } from 'chai';
|
4 | 4 | import { describe, it } from 'mocha';
|
5 | 5 |
|
6 |
| -import { getNamedType, isCompositeType } from '../../type/definition'; |
7 |
| -import { TypeInfo } from '../../utilities/TypeInfo'; |
8 |
| - |
9 | 6 | import { Kind } from '../kinds';
|
10 | 7 | import { parse } from '../parser';
|
11 |
| -import { print } from '../printer'; |
12 |
| -import { visit, visitInParallel, visitWithTypeInfo, BREAK } from '../visitor'; |
| 8 | +import { visit, visitInParallel, BREAK } from '../visitor'; |
13 | 9 |
|
14 | 10 | import { kitchenSinkQuery } from '../../__fixtures__';
|
15 |
| -import { testSchema } from '../../validation/__tests__/harness'; |
16 | 11 |
|
17 | 12 | function checkVisitorFnArgs(ast, args, isEdited) {
|
18 | 13 | const [node, key, parent, path, ancestors] = args;
|
@@ -1309,213 +1304,4 @@ describe('Visitor', () => {
|
1309 | 1304 | ]);
|
1310 | 1305 | });
|
1311 | 1306 | });
|
1312 |
| - |
1313 |
| - describe('visitWithTypeInfo', () => { |
1314 |
| - it('maintains type info during visit', () => { |
1315 |
| - const visited = []; |
1316 |
| - |
1317 |
| - const typeInfo = new TypeInfo(testSchema); |
1318 |
| - |
1319 |
| - const ast = parse( |
1320 |
| - '{ human(id: 4) { name, pets { ... { name } }, unknown } }', |
1321 |
| - ); |
1322 |
| - visit( |
1323 |
| - ast, |
1324 |
| - visitWithTypeInfo(typeInfo, { |
1325 |
| - enter(node) { |
1326 |
| - checkVisitorFnArgs(ast, arguments); |
1327 |
| - const parentType = typeInfo.getParentType(); |
1328 |
| - const type = typeInfo.getType(); |
1329 |
| - const inputType = typeInfo.getInputType(); |
1330 |
| - visited.push([ |
1331 |
| - 'enter', |
1332 |
| - node.kind, |
1333 |
| - node.kind === 'Name' ? node.value : null, |
1334 |
| - parentType ? String(parentType) : null, |
1335 |
| - type ? String(type) : null, |
1336 |
| - inputType ? String(inputType) : null, |
1337 |
| - ]); |
1338 |
| - }, |
1339 |
| - leave(node) { |
1340 |
| - checkVisitorFnArgs(ast, arguments); |
1341 |
| - const parentType = typeInfo.getParentType(); |
1342 |
| - const type = typeInfo.getType(); |
1343 |
| - const inputType = typeInfo.getInputType(); |
1344 |
| - visited.push([ |
1345 |
| - 'leave', |
1346 |
| - node.kind, |
1347 |
| - node.kind === 'Name' ? node.value : null, |
1348 |
| - parentType ? String(parentType) : null, |
1349 |
| - type ? String(type) : null, |
1350 |
| - inputType ? String(inputType) : null, |
1351 |
| - ]); |
1352 |
| - }, |
1353 |
| - }), |
1354 |
| - ); |
1355 |
| - |
1356 |
| - expect(visited).to.deep.equal([ |
1357 |
| - ['enter', 'Document', null, null, null, null], |
1358 |
| - ['enter', 'OperationDefinition', null, null, 'QueryRoot', null], |
1359 |
| - ['enter', 'SelectionSet', null, 'QueryRoot', 'QueryRoot', null], |
1360 |
| - ['enter', 'Field', null, 'QueryRoot', 'Human', null], |
1361 |
| - ['enter', 'Name', 'human', 'QueryRoot', 'Human', null], |
1362 |
| - ['leave', 'Name', 'human', 'QueryRoot', 'Human', null], |
1363 |
| - ['enter', 'Argument', null, 'QueryRoot', 'Human', 'ID'], |
1364 |
| - ['enter', 'Name', 'id', 'QueryRoot', 'Human', 'ID'], |
1365 |
| - ['leave', 'Name', 'id', 'QueryRoot', 'Human', 'ID'], |
1366 |
| - ['enter', 'IntValue', null, 'QueryRoot', 'Human', 'ID'], |
1367 |
| - ['leave', 'IntValue', null, 'QueryRoot', 'Human', 'ID'], |
1368 |
| - ['leave', 'Argument', null, 'QueryRoot', 'Human', 'ID'], |
1369 |
| - ['enter', 'SelectionSet', null, 'Human', 'Human', null], |
1370 |
| - ['enter', 'Field', null, 'Human', 'String', null], |
1371 |
| - ['enter', 'Name', 'name', 'Human', 'String', null], |
1372 |
| - ['leave', 'Name', 'name', 'Human', 'String', null], |
1373 |
| - ['leave', 'Field', null, 'Human', 'String', null], |
1374 |
| - ['enter', 'Field', null, 'Human', '[Pet]', null], |
1375 |
| - ['enter', 'Name', 'pets', 'Human', '[Pet]', null], |
1376 |
| - ['leave', 'Name', 'pets', 'Human', '[Pet]', null], |
1377 |
| - ['enter', 'SelectionSet', null, 'Pet', '[Pet]', null], |
1378 |
| - ['enter', 'InlineFragment', null, 'Pet', 'Pet', null], |
1379 |
| - ['enter', 'SelectionSet', null, 'Pet', 'Pet', null], |
1380 |
| - ['enter', 'Field', null, 'Pet', 'String', null], |
1381 |
| - ['enter', 'Name', 'name', 'Pet', 'String', null], |
1382 |
| - ['leave', 'Name', 'name', 'Pet', 'String', null], |
1383 |
| - ['leave', 'Field', null, 'Pet', 'String', null], |
1384 |
| - ['leave', 'SelectionSet', null, 'Pet', 'Pet', null], |
1385 |
| - ['leave', 'InlineFragment', null, 'Pet', 'Pet', null], |
1386 |
| - ['leave', 'SelectionSet', null, 'Pet', '[Pet]', null], |
1387 |
| - ['leave', 'Field', null, 'Human', '[Pet]', null], |
1388 |
| - ['enter', 'Field', null, 'Human', null, null], |
1389 |
| - ['enter', 'Name', 'unknown', 'Human', null, null], |
1390 |
| - ['leave', 'Name', 'unknown', 'Human', null, null], |
1391 |
| - ['leave', 'Field', null, 'Human', null, null], |
1392 |
| - ['leave', 'SelectionSet', null, 'Human', 'Human', null], |
1393 |
| - ['leave', 'Field', null, 'QueryRoot', 'Human', null], |
1394 |
| - ['leave', 'SelectionSet', null, 'QueryRoot', 'QueryRoot', null], |
1395 |
| - ['leave', 'OperationDefinition', null, null, 'QueryRoot', null], |
1396 |
| - ['leave', 'Document', null, null, null, null], |
1397 |
| - ]); |
1398 |
| - }); |
1399 |
| - |
1400 |
| - it('maintains type info during edit', () => { |
1401 |
| - const visited = []; |
1402 |
| - const typeInfo = new TypeInfo(testSchema); |
1403 |
| - |
1404 |
| - const ast = parse('{ human(id: 4) { name, pets }, alien }'); |
1405 |
| - const editedAST = visit( |
1406 |
| - ast, |
1407 |
| - visitWithTypeInfo(typeInfo, { |
1408 |
| - enter(node) { |
1409 |
| - checkVisitorFnArgs(ast, arguments, /* isEdited */ true); |
1410 |
| - const parentType = typeInfo.getParentType(); |
1411 |
| - const type = typeInfo.getType(); |
1412 |
| - const inputType = typeInfo.getInputType(); |
1413 |
| - visited.push([ |
1414 |
| - 'enter', |
1415 |
| - node.kind, |
1416 |
| - node.kind === 'Name' ? node.value : null, |
1417 |
| - parentType ? String(parentType) : null, |
1418 |
| - type ? String(type) : null, |
1419 |
| - inputType ? String(inputType) : null, |
1420 |
| - ]); |
1421 |
| - |
1422 |
| - // Make a query valid by adding missing selection sets. |
1423 |
| - if ( |
1424 |
| - node.kind === 'Field' && |
1425 |
| - !node.selectionSet && |
1426 |
| - isCompositeType(getNamedType(type)) |
1427 |
| - ) { |
1428 |
| - return { |
1429 |
| - kind: 'Field', |
1430 |
| - alias: node.alias, |
1431 |
| - name: node.name, |
1432 |
| - arguments: node.arguments, |
1433 |
| - directives: node.directives, |
1434 |
| - selectionSet: { |
1435 |
| - kind: 'SelectionSet', |
1436 |
| - selections: [ |
1437 |
| - { |
1438 |
| - kind: 'Field', |
1439 |
| - name: { kind: 'Name', value: '__typename' }, |
1440 |
| - }, |
1441 |
| - ], |
1442 |
| - }, |
1443 |
| - }; |
1444 |
| - } |
1445 |
| - }, |
1446 |
| - leave(node) { |
1447 |
| - checkVisitorFnArgs(ast, arguments, /* isEdited */ true); |
1448 |
| - const parentType = typeInfo.getParentType(); |
1449 |
| - const type = typeInfo.getType(); |
1450 |
| - const inputType = typeInfo.getInputType(); |
1451 |
| - visited.push([ |
1452 |
| - 'leave', |
1453 |
| - node.kind, |
1454 |
| - node.kind === 'Name' ? node.value : null, |
1455 |
| - parentType ? String(parentType) : null, |
1456 |
| - type ? String(type) : null, |
1457 |
| - inputType ? String(inputType) : null, |
1458 |
| - ]); |
1459 |
| - }, |
1460 |
| - }), |
1461 |
| - ); |
1462 |
| - |
1463 |
| - expect(print(ast)).to.deep.equal( |
1464 |
| - print(parse('{ human(id: 4) { name, pets }, alien }')), |
1465 |
| - ); |
1466 |
| - |
1467 |
| - expect(print(editedAST)).to.deep.equal( |
1468 |
| - print( |
1469 |
| - parse( |
1470 |
| - '{ human(id: 4) { name, pets { __typename } }, alien { __typename } }', |
1471 |
| - ), |
1472 |
| - ), |
1473 |
| - ); |
1474 |
| - |
1475 |
| - expect(visited).to.deep.equal([ |
1476 |
| - ['enter', 'Document', null, null, null, null], |
1477 |
| - ['enter', 'OperationDefinition', null, null, 'QueryRoot', null], |
1478 |
| - ['enter', 'SelectionSet', null, 'QueryRoot', 'QueryRoot', null], |
1479 |
| - ['enter', 'Field', null, 'QueryRoot', 'Human', null], |
1480 |
| - ['enter', 'Name', 'human', 'QueryRoot', 'Human', null], |
1481 |
| - ['leave', 'Name', 'human', 'QueryRoot', 'Human', null], |
1482 |
| - ['enter', 'Argument', null, 'QueryRoot', 'Human', 'ID'], |
1483 |
| - ['enter', 'Name', 'id', 'QueryRoot', 'Human', 'ID'], |
1484 |
| - ['leave', 'Name', 'id', 'QueryRoot', 'Human', 'ID'], |
1485 |
| - ['enter', 'IntValue', null, 'QueryRoot', 'Human', 'ID'], |
1486 |
| - ['leave', 'IntValue', null, 'QueryRoot', 'Human', 'ID'], |
1487 |
| - ['leave', 'Argument', null, 'QueryRoot', 'Human', 'ID'], |
1488 |
| - ['enter', 'SelectionSet', null, 'Human', 'Human', null], |
1489 |
| - ['enter', 'Field', null, 'Human', 'String', null], |
1490 |
| - ['enter', 'Name', 'name', 'Human', 'String', null], |
1491 |
| - ['leave', 'Name', 'name', 'Human', 'String', null], |
1492 |
| - ['leave', 'Field', null, 'Human', 'String', null], |
1493 |
| - ['enter', 'Field', null, 'Human', '[Pet]', null], |
1494 |
| - ['enter', 'Name', 'pets', 'Human', '[Pet]', null], |
1495 |
| - ['leave', 'Name', 'pets', 'Human', '[Pet]', null], |
1496 |
| - ['enter', 'SelectionSet', null, 'Pet', '[Pet]', null], |
1497 |
| - ['enter', 'Field', null, 'Pet', 'String!', null], |
1498 |
| - ['enter', 'Name', '__typename', 'Pet', 'String!', null], |
1499 |
| - ['leave', 'Name', '__typename', 'Pet', 'String!', null], |
1500 |
| - ['leave', 'Field', null, 'Pet', 'String!', null], |
1501 |
| - ['leave', 'SelectionSet', null, 'Pet', '[Pet]', null], |
1502 |
| - ['leave', 'Field', null, 'Human', '[Pet]', null], |
1503 |
| - ['leave', 'SelectionSet', null, 'Human', 'Human', null], |
1504 |
| - ['leave', 'Field', null, 'QueryRoot', 'Human', null], |
1505 |
| - ['enter', 'Field', null, 'QueryRoot', 'Alien', null], |
1506 |
| - ['enter', 'Name', 'alien', 'QueryRoot', 'Alien', null], |
1507 |
| - ['leave', 'Name', 'alien', 'QueryRoot', 'Alien', null], |
1508 |
| - ['enter', 'SelectionSet', null, 'Alien', 'Alien', null], |
1509 |
| - ['enter', 'Field', null, 'Alien', 'String!', null], |
1510 |
| - ['enter', 'Name', '__typename', 'Alien', 'String!', null], |
1511 |
| - ['leave', 'Name', '__typename', 'Alien', 'String!', null], |
1512 |
| - ['leave', 'Field', null, 'Alien', 'String!', null], |
1513 |
| - ['leave', 'SelectionSet', null, 'Alien', 'Alien', null], |
1514 |
| - ['leave', 'Field', null, 'QueryRoot', 'Alien', null], |
1515 |
| - ['leave', 'SelectionSet', null, 'QueryRoot', 'QueryRoot', null], |
1516 |
| - ['leave', 'OperationDefinition', null, null, 'QueryRoot', null], |
1517 |
| - ['leave', 'Document', null, null, null, null], |
1518 |
| - ]); |
1519 |
| - }); |
1520 |
| - }); |
1521 | 1307 | });
|
0 commit comments