Skip to content

Commit dc3353e

Browse files
committed
Test fulfilled meta field in TypeInfo
1 parent 1788e53 commit dc3353e

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

src/utilities/__tests__/TypeInfo-test.ts

+65
Original file line numberDiff line numberDiff line change
@@ -457,4 +457,69 @@ describe('visitWithTypeInfo', () => {
457457
['leave', 'SelectionSet', null, 'Human', 'Human'],
458458
]);
459459
});
460+
461+
it('supports traversals of __fulfilled meta-field', () => {
462+
const humanType = testSchema.getType('Human');
463+
invariant(humanType != null);
464+
465+
const typeInfo = new TypeInfo(testSchema, humanType);
466+
467+
const ast = parse('{ __fulfilled, pets { __fulfilled(label: "pet") } }');
468+
const operationNode = ast.definitions[0];
469+
invariant(operationNode.kind === 'OperationDefinition');
470+
471+
const visited: Array<any> = [];
472+
visit(
473+
operationNode.selectionSet,
474+
visitWithTypeInfo(typeInfo, {
475+
enter(node) {
476+
const parentType = typeInfo.getParentType();
477+
const type = typeInfo.getType();
478+
visited.push([
479+
'enter',
480+
node.kind,
481+
node.kind === 'Name' ? node.value : null,
482+
String(parentType),
483+
String(type),
484+
]);
485+
},
486+
leave(node) {
487+
const parentType = typeInfo.getParentType();
488+
const type = typeInfo.getType();
489+
visited.push([
490+
'leave',
491+
node.kind,
492+
node.kind === 'Name' ? node.value : null,
493+
String(parentType),
494+
String(type),
495+
]);
496+
},
497+
}),
498+
);
499+
500+
expect(visited).to.deep.equal([
501+
['enter', 'SelectionSet', null, 'Human', 'Human'],
502+
['enter', 'Field', null, 'Human', 'Boolean!'],
503+
['enter', 'Name', '__fulfilled', 'Human', 'Boolean!'],
504+
['leave', 'Name', '__fulfilled', 'Human', 'Boolean!'],
505+
['leave', 'Field', null, 'Human', 'Boolean!'],
506+
['enter', 'Field', null, 'Human', '[Pet]'],
507+
['enter', 'Name', 'pets', 'Human', '[Pet]'],
508+
['leave', 'Name', 'pets', 'Human', '[Pet]'],
509+
['enter', 'SelectionSet', null, 'Pet', '[Pet]'],
510+
['enter', 'Field', null, 'Pet', 'Boolean!'],
511+
['enter', 'Name', '__fulfilled', 'Pet', 'Boolean!'],
512+
['leave', 'Name', '__fulfilled', 'Pet', 'Boolean!'],
513+
['enter', 'Argument', null, 'Pet', 'Boolean!'],
514+
['enter', 'Name', 'label', 'Pet', 'Boolean!'],
515+
['leave', 'Name', 'label', 'Pet', 'Boolean!'],
516+
['enter', 'StringValue', null, 'Pet', 'Boolean!'],
517+
['leave', 'StringValue', null, 'Pet', 'Boolean!'],
518+
['leave', 'Argument', null, 'Pet', 'Boolean!'],
519+
['leave', 'Field', null, 'Pet', 'Boolean!'],
520+
['leave', 'SelectionSet', null, 'Pet', '[Pet]'],
521+
['leave', 'Field', null, 'Human', '[Pet]'],
522+
['leave', 'SelectionSet', null, 'Human', 'Human'],
523+
]);
524+
});
460525
});

0 commit comments

Comments
 (0)