Minor refactors for printer-graphql.js (#14233)
This commit is contained in:
1 parent
2ed898dfb7
commit
f65700ff88
1 file changed
+28
-35
@@ -33,22 +33,9 @@ function genericPrint(path, options, print) {
|
||||
hasOperation && !hasName && isNonEmptyArray(node.variableDefinitions)
|
||||
? " "
|
||||
: "",
|
||||
isNonEmptyArray(node.variableDefinitions)
|
||||
? group([
|
||||
"(",
|
||||
indent([
|
||||
softline,
|
||||
join(
|
||||
[ifBreak("", ", "), softline],
|
||||
path.map(print, "variableDefinitions")
|
||||
),
|
||||
]),
|
||||
softline,
|
||||
")",
|
||||
])
|
||||
: "",
|
||||
printVariableDefinitions(path, print),
|
||||
printDirectives(path, print, node),
|
||||
node.selectionSet ? (!hasOperation && !hasName ? "" : " ") : "",
|
||||
!hasOperation && !hasName ? "" : " ",
|
||||
print("selectionSet"),
|
||||
];
|
||||
}
|
||||
@@ -56,20 +43,7 @@ function genericPrint(path, options, print) {
|
||||
return [
|
||||
"fragment ",
|
||||
print("name"),
|
||||
isNonEmptyArray(node.variableDefinitions)
|
||||
? group([
|
||||
"(",
|
||||
indent([
|
||||
softline,
|
||||
join(
|
||||
[ifBreak("", ", "), softline],
|
||||
path.map(print, "variableDefinitions")
|
||||
),
|
||||
]),
|
||||
softline,
|
||||
")",
|
||||
])
|
||||
: "",
|
||||
printVariableDefinitions(path, print),
|
||||
" on ",
|
||||
print("typeCondition"),
|
||||
printDirectives(path, print, node),
|
||||
@@ -158,21 +132,21 @@ function genericPrint(path, options, print) {
|
||||
"]",
|
||||
]);
|
||||
|
||||
case "ObjectValue":
|
||||
case "ObjectValue": {
|
||||
const bracketSpace =
|
||||
options.bracketSpacing && node.fields.length > 0 ? " " : "";
|
||||
return group([
|
||||
"{",
|
||||
options.bracketSpacing && node.fields.length > 0 ? " " : "",
|
||||
bracketSpace,
|
||||
indent([
|
||||
softline,
|
||||
join([ifBreak("", ", "), softline], path.map(print, "fields")),
|
||||
]),
|
||||
softline,
|
||||
ifBreak(
|
||||
"",
|
||||
options.bracketSpacing && node.fields.length > 0 ? " " : ""
|
||||
),
|
||||
ifBreak("", bracketSpace),
|
||||
"}",
|
||||
]);
|
||||
}
|
||||
|
||||
case "ObjectField":
|
||||
case "Argument":
|
||||
@@ -506,6 +480,25 @@ function printInterfaces(path, options, print) {
|
||||
return parts;
|
||||
}
|
||||
|
||||
function printVariableDefinitions(path, print) {
|
||||
const { node } = path;
|
||||
if (!isNonEmptyArray(node.variableDefinitions)) {
|
||||
return "";
|
||||
}
|
||||
return group([
|
||||
"(",
|
||||
indent([
|
||||
softline,
|
||||
join(
|
||||
[ifBreak("", ", "), softline],
|
||||
path.map(print, "variableDefinitions")
|
||||
),
|
||||
]),
|
||||
softline,
|
||||
")",
|
||||
]);
|
||||
}
|
||||
|
||||
function clean(node, newNode /* , parent */) {
|
||||
// We print single line `""" string """` as multiple line string,
|
||||
// and the parser ignores space in multiple line string
|
||||
|
||||
Reference in new issue
Block a user