Skip to content

Commit

Permalink
printer: simplify printing of query short form
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Mar 13, 2021
1 parent e6f20da commit c7144cc
Showing 1 changed file with 10 additions and 7 deletions.
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

0 comments on commit c7144cc

Please sign in to comment.