Add support for --trailing-comma for GraphQL (#2254)

Fixes #2251
master
Christopher Chedeau 2017-06-24 11:20:45 -07:00 committed by GitHub
parent b464189fb4
commit cc85769231
4 changed files with 150 additions and 0 deletions

View File

@ -90,6 +90,7 @@ function genericPrint(path, options, print) {
)
])
),
options.trailingComma === "none" ? "" : ifBreak(","),
softline,
")"
])
@ -134,6 +135,7 @@ function genericPrint(path, options, print) {
)
])
),
options.trailingComma === "none" ? "" : ifBreak(","),
softline,
"]"
])
@ -153,6 +155,7 @@ function genericPrint(path, options, print) {
)
])
),
options.trailingComma === "none" ? "" : ifBreak(","),
softline,
ifBreak("", options.bracketSpacing && n.fields.length > 0 ? " " : ""),
"}"
@ -185,6 +188,7 @@ function genericPrint(path, options, print) {
)
])
),
options.trailingComma === "none" ? "" : ifBreak(","),
softline,
")"
])

View File

@ -0,0 +1,127 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`trailing.graphql 1`] = `
fragment Visit on HighlightedVisit
@argumentDefinitions(
count: {type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301}
test: [{type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301}]
) {
cover_photo {
image(
width: $PROJECT_UNIT_CARD_SIZE,
height: $PROJECT_UNIT_CARD_SIZE,
sizing: "cover-fill",
scale: $scale,
) {
uri
}
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fragment Visit on HighlightedVisit
@argumentDefinitions(
count: {
type: "Int",
defaultValue: 20,
someSuperSuperSuperSuperLongType: 301
},
test: [
{ type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301 }
]
) {
cover_photo {
image(
width: $PROJECT_UNIT_CARD_SIZE,
height: $PROJECT_UNIT_CARD_SIZE,
sizing: "cover-fill",
scale: $scale
) {
uri
}
}
}
`;
exports[`trailing.graphql 2`] = `
fragment Visit on HighlightedVisit
@argumentDefinitions(
count: {type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301}
test: [{type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301}]
) {
cover_photo {
image(
width: $PROJECT_UNIT_CARD_SIZE,
height: $PROJECT_UNIT_CARD_SIZE,
sizing: "cover-fill",
scale: $scale,
) {
uri
}
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fragment Visit on HighlightedVisit
@argumentDefinitions(
count: {
type: "Int",
defaultValue: 20,
someSuperSuperSuperSuperLongType: 301,
},
test: [
{ type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301 },
],
) {
cover_photo {
image(
width: $PROJECT_UNIT_CARD_SIZE,
height: $PROJECT_UNIT_CARD_SIZE,
sizing: "cover-fill",
scale: $scale,
) {
uri
}
}
}
`;
exports[`trailing.graphql 3`] = `
fragment Visit on HighlightedVisit
@argumentDefinitions(
count: {type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301}
test: [{type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301}]
) {
cover_photo {
image(
width: $PROJECT_UNIT_CARD_SIZE,
height: $PROJECT_UNIT_CARD_SIZE,
sizing: "cover-fill",
scale: $scale,
) {
uri
}
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fragment Visit on HighlightedVisit
@argumentDefinitions(
count: {
type: "Int",
defaultValue: 20,
someSuperSuperSuperSuperLongType: 301,
},
test: [
{ type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301 },
],
) {
cover_photo {
image(
width: $PROJECT_UNIT_CARD_SIZE,
height: $PROJECT_UNIT_CARD_SIZE,
sizing: "cover-fill",
scale: $scale,
) {
uri
}
}
}
`;

View File

@ -0,0 +1,3 @@
run_spec(__dirname, { parser: "graphql" });
run_spec(__dirname, { parser: "graphql", trailingComma: "all" });
run_spec(__dirname, { parser: "graphql", trailingComma: "es5" });

View File

@ -0,0 +1,16 @@
fragment Visit on HighlightedVisit
@argumentDefinitions(
count: {type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301}
test: [{type: "Int", defaultValue: 20, someSuperSuperSuperSuperLongType: 301}]
) {
cover_photo {
image(
width: $PROJECT_UNIT_CARD_SIZE,
height: $PROJECT_UNIT_CARD_SIZE,
sizing: "cover-fill",
scale: $scale,
) {
uri
}
}
}