Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

printer: simplify printing of query short form #2963

Merged
merged 1 commit into from Mar 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/language/printer.js
Expand Up @@ -26,16 +26,19 @@ const printDocASTReducer: any = {

OperationDefinition: {
leave(node) {
const op = node.operation;
const name = node.name;
const varDefs = wrap('(', join(node.variableDefinitions, ', '), ')');
const directives = join(node.directives, ' ');
const selectionSet = node.selectionSet;
const prefix = join(
[
node.operation,
join([node.name, varDefs]),
join(node.directives, ' '),
],
' ',
);

// Anonymous queries with no directives or variable definitions can use
// the query short form.
return !name && !directives && !varDefs && op === 'query'
? selectionSet
: join([op, join([name, varDefs]), directives, selectionSet], ' ');
return (prefix === 'query' ? '' : prefix + ' ') + node.selectionSet;
},
},

Expand Down