Skip to content

Commit eb60915

Browse files
author
Adrian Zgorzalek
committed
Don't special case single argument and don't use to separate arguments
1 parent 5c31fd3 commit eb60915

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

src/language/__tests__/printer-test.js

+17-15
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ describe('Printer: Query document', () => {
6060
'query ($foo: TestType) @testDirective { id, name }',
6161
);
6262
expect(print(queryAstWithArtifacts)).to.equal(dedent`
63-
query ($foo: TestType) @testDirective {
63+
query (
64+
$foo: TestType
65+
) @testDirective {
6466
id
6567
name
6668
}
@@ -70,7 +72,9 @@ describe('Printer: Query document', () => {
7072
'mutation ($foo: TestType) @testDirective { id, name }',
7173
);
7274
expect(print(mutationAstWithArtifacts)).to.equal(dedent`
73-
mutation ($foo: TestType) @testDirective {
75+
mutation (
76+
$foo: TestType
77+
) @testDirective {
7478
id
7579
name
7680
}
@@ -82,7 +86,9 @@ describe('Printer: Query document', () => {
8286
'query ($foo: TestType = {a: 123} @testDirective(if: true) @test) { id }',
8387
);
8488
expect(print(queryAstWithVariableDirective)).to.equal(dedent`
85-
query ($foo: TestType = {a: 123} @testDirective(if: true) @test) {
89+
query (
90+
$foo: TestType = {a: 123} @testDirective(if: true) @test
91+
) {
8692
id
8793
}
8894
`);
@@ -96,7 +102,9 @@ describe('Printer: Query document', () => {
96102
},
97103
);
98104
expect(print(queryAstWithVariableDirective)).to.equal(dedent`
99-
fragment Foo($foo: TestType @test) on TestType @testDirective {
105+
fragment Foo(
106+
$foo: TestType @test
107+
) on TestType @testDirective {
100108
id
101109
}
102110
`);
@@ -157,24 +165,16 @@ describe('Printer: Query document', () => {
157165
fragment Foo($a: ComplexType, $b: Boolean = false) on TestType {
158166
id
159167
}
160-
161-
fragment Simple($a: Boolean = true) on TestType {
162-
id
163-
}
164168
`,
165169
{ experimentalFragmentVariables: true },
166170
);
167171
expect(print(fragmentWithVariable)).to.equal(dedent`
168172
fragment Foo(
169-
$a: ComplexType,
173+
$a: ComplexType
170174
$b: Boolean = false
171175
) on TestType {
172176
id
173177
}
174-
175-
fragment Simple($a: Boolean = true) on TestType {
176-
id
177-
}
178178
`);
179179
});
180180

@@ -186,7 +186,7 @@ describe('Printer: Query document', () => {
186186
expect(printed).to.equal(
187187
dedent(String.raw`
188188
query queryName(
189-
$foo: ComplexType,
189+
$foo: ComplexType
190190
$site: Site = MOBILE
191191
) @onQuery {
192192
whoever123is: node(id: [123, 456]) {
@@ -217,7 +217,9 @@ describe('Printer: Query document', () => {
217217
}
218218
}
219219
220-
subscription StoryLikeSubscription($input: StoryLikeSubscribeInput) @onSubscription {
220+
subscription StoryLikeSubscription(
221+
$input: StoryLikeSubscribeInput
222+
) @onSubscription {
221223
storyLikeSubscribe(input: $input) {
222224
story {
223225
likers {

src/language/printer.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,11 @@ function printBlockString(value, isDescription) {
285285
}
286286

287287
/**
288-
* Prints variables one per line with a trailing comma, when there is more
289-
* than one argument. Otherwise print inline.
288+
* Prints variables one per line.
290289
*/
291290
function printVariableDefinitions(args) {
292291
if (!args || args.length === 0) {
293292
return '';
294293
}
295-
if (args.length === 1) {
296-
return '(' + args[0] + ')';
297-
}
298-
return '(\n' + indent(join(args, ',\n')) + '\n)';
294+
return '(\n' + indent(join(args, '\n')) + '\n)';
299295
}

0 commit comments

Comments
 (0)