diff --git a/src/printer-graphql.js b/src/printer-graphql.js index 503d378a..b5e61710 100644 --- a/src/printer-graphql.js +++ b/src/printer-graphql.js @@ -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, ")" ]) diff --git a/tests/graphql_trailing_comma/__snapshots__/jsfmt.spec.js.snap b/tests/graphql_trailing_comma/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 00000000..ee215ae2 --- /dev/null +++ b/tests/graphql_trailing_comma/__snapshots__/jsfmt.spec.js.snap @@ -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 + } + } +} +`; diff --git a/tests/graphql_trailing_comma/jsfmt.spec.js b/tests/graphql_trailing_comma/jsfmt.spec.js new file mode 100644 index 00000000..830eb7ce --- /dev/null +++ b/tests/graphql_trailing_comma/jsfmt.spec.js @@ -0,0 +1,3 @@ +run_spec(__dirname, { parser: "graphql" }); +run_spec(__dirname, { parser: "graphql", trailingComma: "all" }); +run_spec(__dirname, { parser: "graphql", trailingComma: "es5" }); diff --git a/tests/graphql_trailing_comma/trailing.graphql b/tests/graphql_trailing_comma/trailing.graphql new file mode 100644 index 00000000..43e90261 --- /dev/null +++ b/tests/graphql_trailing_comma/trailing.graphql @@ -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 + } + } +}