Skip to content

Commit

Permalink
Don't special case single argument and don't use to separate arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrian Zgorzalek committed Nov 5, 2018
1 parent 3d9231d commit 1d266c4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
32 changes: 17 additions & 15 deletions src/language/__tests__/printer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ describe('Printer: Query document', () => {
'query ($foo: TestType) @testDirective { id, name }',
);
expect(print(queryAstWithArtifacts)).to.equal(dedent`
query ($foo: TestType) @testDirective {
query (
$foo: TestType
) @testDirective {
id
name
}
Expand All @@ -70,7 +72,9 @@ describe('Printer: Query document', () => {
'mutation ($foo: TestType) @testDirective { id, name }',
);
expect(print(mutationAstWithArtifacts)).to.equal(dedent`
mutation ($foo: TestType) @testDirective {
mutation (
$foo: TestType
) @testDirective {
id
name
}
Expand All @@ -82,7 +86,9 @@ describe('Printer: Query document', () => {
'query ($foo: TestType = {a: 123} @testDirective(if: true) @test) { id }',
);
expect(print(queryAstWithVariableDirective)).to.equal(dedent`
query ($foo: TestType = {a: 123} @testDirective(if: true) @test) {
query (
$foo: TestType = {a: 123} @testDirective(if: true) @test
) {
id
}
`);
Expand All @@ -96,7 +102,9 @@ describe('Printer: Query document', () => {
},
);
expect(print(queryAstWithVariableDirective)).to.equal(dedent`
fragment Foo($foo: TestType @test) on TestType @testDirective {
fragment Foo(
$foo: TestType @test
) on TestType @testDirective {
id
}
`);
Expand Down Expand Up @@ -157,24 +165,16 @@ describe('Printer: Query document', () => {
fragment Foo($a: ComplexType, $b: Boolean = false) on TestType {
id
}
fragment Simple($a: Boolean = true) on TestType {
id
}
`,
{ experimentalFragmentVariables: true },
);
expect(print(fragmentWithVariable)).to.equal(dedent`
fragment Foo(
$a: ComplexType,
$a: ComplexType
$b: Boolean = false
) on TestType {
id
}
fragment Simple($a: Boolean = true) on TestType {
id
}
`);
});

Expand All @@ -186,7 +186,7 @@ describe('Printer: Query document', () => {
expect(printed).to.equal(
dedent(String.raw`
query queryName(
$foo: ComplexType,
$foo: ComplexType
$site: Site = MOBILE
) @onQuery {
whoever123is: node(id: [123, 456]) {
Expand Down Expand Up @@ -217,7 +217,9 @@ describe('Printer: Query document', () => {
}
}
subscription StoryLikeSubscription($input: StoryLikeSubscribeInput) @onSubscription {
subscription StoryLikeSubscription(
$input: StoryLikeSubscribeInput
) @onSubscription {
storyLikeSubscribe(input: $input) {
story {
likers {
Expand Down
8 changes: 2 additions & 6 deletions src/language/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,15 +285,11 @@ function printBlockString(value, isDescription) {
}

/**
* Prints variables one per line with a trailing comma, when there is more
* than one argument. Otherwise print inline.
* Prints variables one per line.
*/
function printVariableDefinitions(args) {
if (!args || args.length === 0) {
return '';
}
if (args.length === 1) {
return '(' + args[0] + ')';
}
return '(\n' + indent(join(args, ',\n')) + '\n)';
return '(\n' + indent(join(args, '\n')) + '\n)';
}

0 comments on commit 1d266c4

Please sign in to comment.