Skip to content

Commit

Permalink
add test for visiting default value
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Aug 20, 2024
1 parent 8411834 commit 2fff4bd
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions src/utilities/__tests__/TypeInfo-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ describe('visitWithTypeInfo', () => {
`
query {
...Foo(x: 4)
...Bar
}
fragment Foo(
$x: ID!
Expand Down Expand Up @@ -621,4 +622,104 @@ describe('visitWithTypeInfo', () => {
['leave', 'Document', null, 'undefined', 'undefined'],
]);
});

it('supports traversals of fragment arguments with default-value', () => {
const typeInfo = new TypeInfo(testSchema);

const ast = parse(
`
query {
...Foo
}
fragment Foo(
$x: ID = 4
) on QueryRoot {
human(id: $x) { name }
}
`,
{ experimentalFragmentArguments: true },
);

const visited: Array<any> = [];
visit(
ast,
visitWithTypeInfo(typeInfo, {
enter(node) {
const type = typeInfo.getType();
const inputType = typeInfo.getInputType();
visited.push([
'enter',
node.kind,
node.kind === 'Name' ? node.value : null,
String(type),
String(inputType),
]);
},
leave(node) {
const type = typeInfo.getType();
const inputType = typeInfo.getInputType();
visited.push([
'leave',
node.kind,
node.kind === 'Name' ? node.value : null,
String(type),
String(inputType),
]);
},
}),
);

expect(visited).to.deep.equal([
['enter', 'Document', null, 'undefined', 'undefined'],
['enter', 'OperationDefinition', null, 'QueryRoot', 'undefined'],
['enter', 'SelectionSet', null, 'QueryRoot', 'undefined'],
['enter', 'FragmentSpread', null, 'QueryRoot', 'undefined'],
['enter', 'Name', 'Foo', 'QueryRoot', 'undefined'],
['leave', 'Name', 'Foo', 'QueryRoot', 'undefined'],
['leave', 'FragmentSpread', null, 'QueryRoot', 'undefined'],
['leave', 'SelectionSet', null, 'QueryRoot', 'undefined'],
['leave', 'OperationDefinition', null, 'QueryRoot', 'undefined'],
['enter', 'FragmentDefinition', null, 'QueryRoot', 'undefined'],
['enter', 'Name', 'Foo', 'QueryRoot', 'undefined'],
['leave', 'Name', 'Foo', 'QueryRoot', 'undefined'],
['enter', 'VariableDefinition', null, 'QueryRoot', 'ID'],
['enter', 'Variable', null, 'QueryRoot', 'ID'],
['enter', 'Name', 'x', 'QueryRoot', 'ID'],
['leave', 'Name', 'x', 'QueryRoot', 'ID'],
['leave', 'Variable', null, 'QueryRoot', 'ID'],
['enter', 'NamedType', null, 'QueryRoot', 'ID'],
['enter', 'Name', 'ID', 'QueryRoot', 'ID'],
['leave', 'Name', 'ID', 'QueryRoot', 'ID'],
['leave', 'NamedType', null, 'QueryRoot', 'ID'],
['enter', 'IntValue', null, 'QueryRoot', 'ID'],
['leave', 'IntValue', null, 'QueryRoot', 'ID'],
['leave', 'VariableDefinition', null, 'QueryRoot', 'ID'],
['enter', 'NamedType', null, 'QueryRoot', 'undefined'],
['enter', 'Name', 'QueryRoot', 'QueryRoot', 'undefined'],
['leave', 'Name', 'QueryRoot', 'QueryRoot', 'undefined'],
['leave', 'NamedType', null, 'QueryRoot', 'undefined'],
['enter', 'SelectionSet', null, 'QueryRoot', 'undefined'],
['enter', 'Field', null, 'Human', 'undefined'],
['enter', 'Name', 'human', 'Human', 'undefined'],
['leave', 'Name', 'human', 'Human', 'undefined'],
['enter', 'Argument', null, 'Human', 'ID'],
['enter', 'Name', 'id', 'Human', 'ID'],
['leave', 'Name', 'id', 'Human', 'ID'],
['enter', 'Variable', null, 'Human', 'ID'],
['enter', 'Name', 'x', 'Human', 'ID'],
['leave', 'Name', 'x', 'Human', 'ID'],
['leave', 'Variable', null, 'Human', 'ID'],
['leave', 'Argument', null, 'Human', 'ID'],
['enter', 'SelectionSet', null, 'Human', 'undefined'],
['enter', 'Field', null, 'String', 'undefined'],
['enter', 'Name', 'name', 'String', 'undefined'],
['leave', 'Name', 'name', 'String', 'undefined'],
['leave', 'Field', null, 'String', 'undefined'],
['leave', 'SelectionSet', null, 'Human', 'undefined'],
['leave', 'Field', null, 'Human', 'undefined'],
['leave', 'SelectionSet', null, 'QueryRoot', 'undefined'],
['leave', 'FragmentDefinition', null, 'QueryRoot', 'undefined'],
['leave', 'Document', null, 'undefined', 'undefined'],
]);
});
});

0 comments on commit 2fff4bd

Please sign in to comment.