Repository: graphql/graphql-js
Pull request #3456 (2022-01-12 18:40:41)

print: add spaces inside input object
Matches prettier output, see:
https://prettier.io/playground/#N4Igxg9gdgLgprEAuEwA6UAEmCGAKHAJwHMlNgckBGAXwEoMaQAaECABxgEtoBnZUEUIQA7gAUiCfihwAbETgCe-VgCNCOMAGs4MAMo4AtnAAyXKHGQAzObzhqN23XvabzxZDEIBXeyDiGqnAAJsEhJjhQxN44xHAAYhCEhjgw3FHIIDjeMBAsIAAWMIayAOoFXPC8rmBwelKVXABulYqZYLwqIOZ2hDBiGsQp1rZ+AFa8AB567rJwAIreEPAjsnasroS9mcQa7AUAjrL57ITmMKVcwTAFyAAcAAwbwnale5mncL1NlqwHS-ABhxpFleABaCwhEL5Qhwf5cWEDWLDJA2NZ+OyGLieHwY2YLAGWVGjVgwHCqS7XW5IABMpI0XFk7gAwhBDCj-LwAKz5bx2AAq5OkaPWICavgAklAwrA9GAzpwAILSvQwRRzVZ2Gg0IA

IvanGoncharov: Postponed until `17.0.0-alpha.1`.
netlify[bot]: ### <span aria-hidden="true">👷</span> Deploy Preview for *compassionate-pike-271cb3* processing.


|  Name | Link |
|---------------------------------|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | 791cece48374ca1ecf4e255e34970bcd51d2be5d |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/sites/compassionate-pike-271cb3/deploys/626974612f30f500094af849 |

Patch:
diff --git a/src/language/printer.ts b/src/language/printer.ts
index e95c118d..38cb2544 100644
--- a/src/language/printer.ts
+++ b/src/language/printer.ts
@@ -116,7 +116,7 @@ const printDocASTReducer: ASTReducer<string> = {
   NullValue: { leave: () => 'null' },
   EnumValue: { leave: ({ value }) => value },
   ListValue: { leave: ({ values }) => '[' + join(values, ', ') + ']' },
-  ObjectValue: { leave: ({ fields }) => '{' + join(fields, ', ') + '}' },
+  ObjectValue: { leave: ({ fields }) => '{ ' + join(fields, ', ') + ' }' },
   ObjectField: { leave: ({ name, value }) => name + ': ' + value },
 
   // Directive


Test patch:
diff --git a/src/language/__tests__/printer-test.ts b/src/language/__tests__/printer-test.ts
index 227e90dd..73e760d6 100644
--- a/src/language/__tests__/printer-test.ts
+++ b/src/language/__tests__/printer-test.ts
@@ -66,10 +66,10 @@ describe('Printer: Query document', () => {
 
   it('prints query with variable directives', () => {
     const queryASTWithVariableDirective = parse(
-      'query ($foo: TestType = {a: 123} @testDirective(if: true) @test) { id }',
+      '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
       }
     `);
@@ -196,9 +196,9 @@ describe('Printer: Query document', () => {
         foo(
           size: $size
           bar: $b
-          obj: {key: "value", block: """
+          obj: { key: "value", block: """
           block string uses \"""
-          """}
+          """ }
         )
       }
 
diff --git a/src/language/__tests__/schema-printer-test.ts b/src/language/__tests__/schema-printer-test.ts
index 49a32693..7272b2f2 100644
--- a/src/language/__tests__/schema-printer-test.ts
+++ b/src/language/__tests__/schema-printer-test.ts
@@ -59,7 +59,7 @@ describe('Printer: SDL document', () => {
         three(argument: InputType, other: String): Int
         four(argument: String = "string"): String
         five(argument: [String] = ["string", "string"]): String
-        six(argument: InputType = {key: "value"}): Type
+        six(argument: InputType = { key: "value" }): Type
         seven(argument: Int = null): Type
       }
 
diff --git a/src/type/__tests__/introspection-test.ts b/src/type/__tests__/introspection-test.ts
index 741d9c00..df431daf 100644
--- a/src/type/__tests__/introspection-test.ts
+++ b/src/type/__tests__/introspection-test.ts
@@ -1086,7 +1086,7 @@ describe('Introspection', () => {
     const schema = buildSchema(`
       input InputObjectWithDefaultValues {
         a: String = "Emoji: \\u{1F600}"
-        b: Complex = {x: ["abc"], y: 123}
+        b: Complex = { x: ["abc"], y: 123 }
       }
 
       input Complex {
@@ -1120,7 +1120,7 @@ describe('Introspection', () => {
             },
             {
               name: 'b',
-              defaultValue: '{x: ["abc"], y: 123}',
+              defaultValue: '{ x: ["abc"], y: 123 }',
             },
           ],
         },
diff --git a/src/type/__tests__/scalars-test.ts b/src/type/__tests__/scalars-test.ts
index 4d563aee..eda64afa 100644
--- a/src/type/__tests__/scalars-test.ts
+++ b/src/type/__tests__/scalars-test.ts
@@ -99,7 +99,7 @@ describe('Type System: Specified scalar types', () => {
         'Int cannot represent non-integer value: [1]',
       );
       expect(() => parseLiteral('{ value: 1 }')).to.throw(
-        'Int cannot represent non-integer value: {value: 1}',
+        'Int cannot represent non-integer value: { value: 1 }',
       );
       expect(() => parseLiteral('ENUM_VALUE')).to.throw(
         'Int cannot represent non-integer value: ENUM_VALUE',
@@ -259,7 +259,7 @@ describe('Type System: Specified scalar types', () => {
         'Float cannot represent non numeric value: [0.1]',
       );
       expect(() => parseLiteral('{ value: 0.1 }')).to.throw(
-        'Float cannot represent non numeric value: {value: 0.1}',
+        'Float cannot represent non numeric value: { value: 0.1 }',
       );
       expect(() => parseLiteral('ENUM_VALUE')).to.throw(
         'Float cannot represent non numeric value: ENUM_VALUE',
@@ -366,7 +366,7 @@ describe('Type System: Specified scalar types', () => {
         'String cannot represent a non string value: ["foo"]',
       );
       expect(() => parseLiteral('{ value: "foo" }')).to.throw(
-        'String cannot represent a non string value: {value: "foo"}',
+        'String cannot represent a non string value: { value: "foo" }',
       );
       expect(() => parseLiteral('ENUM_VALUE')).to.throw(
         'String cannot represent a non string value: ENUM_VALUE',
@@ -484,7 +484,7 @@ describe('Type System: Specified scalar types', () => {
         'Boolean cannot represent a non boolean value: [false]',
       );
       expect(() => parseLiteral('{ value: false }')).to.throw(
-        'Boolean cannot represent a non boolean value: {value: false}',
+        'Boolean cannot represent a non boolean value: { value: false }',
       );
       expect(() => parseLiteral('ENUM_VALUE')).to.throw(
         'Boolean cannot represent a non boolean value: ENUM_VALUE',
@@ -599,7 +599,7 @@ describe('Type System: Specified scalar types', () => {
         'ID cannot represent a non-string and non-integer value: ["1"]',
       );
       expect(() => parseLiteral('{ value: "1" }')).to.throw(
-        'ID cannot represent a non-string and non-integer value: {value: "1"}',
+        'ID cannot represent a non-string and non-integer value: { value: "1" }',
       );
       expect(() => parseLiteral('ENUM_VALUE')).to.throw(
         'ID cannot represent a non-string and non-integer value: ENUM_VALUE',
diff --git a/src/utilities/__tests__/buildClientSchema-test.ts b/src/utilities/__tests__/buildClientSchema-test.ts
index 7d178115..b50cdf66 100644
--- a/src/utilities/__tests__/buildClientSchema-test.ts
+++ b/src/utilities/__tests__/buildClientSchema-test.ts
@@ -443,7 +443,7 @@ describe('Type System: build schema from introspection', () => {
       type Query {
         defaultInt(intArg: Int = 30): String
         defaultList(listArg: [Int] = [1, 2, 3]): String
-        defaultObject(objArg: Geo = {lat: 37.485, lon: -122.148}): String
+        defaultObject(objArg: Geo = { lat: 37.485, lon: -122.148 }): String
         defaultNull(intArg: Int = null): String
         noDefault(intArg: Int): String
       }
diff --git a/src/utilities/__tests__/findBreakingChanges-test.ts b/src/utilities/__tests__/findBreakingChanges-test.ts
index 5a7956ae..6c26e24a 100644
--- a/src/utilities/__tests__/findBreakingChanges-test.ts
+++ b/src/utilities/__tests__/findBreakingChanges-test.ts
@@ -961,7 +961,7 @@ describe('findDangerousChanges', () => {
       {
         type: DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE,
         description:
-          'Type1.field1 arg complexObject has changed defaultValue from {innerInputArray: [{arrayField: [1, 2, 3]}]} to {innerInputArray: [{arrayField: [3, 2, 1]}]}.',
+          'Type1.field1 arg complexObject has changed defaultValue from { innerInputArray: [{ arrayField: [1, 2, 3] }] } to { innerInputArray: [{ arrayField: [3, 2, 1] }] }.',
       },
     ]);
   });
diff --git a/src/utilities/__tests__/sortValueNode-test.ts b/src/utilities/__tests__/sortValueNode-test.ts
index 5bda137d..c55a9be9 100644
--- a/src/utilities/__tests__/sortValueNode-test.ts
+++ b/src/utilities/__tests__/sortValueNode-test.ts
@@ -28,13 +28,15 @@ describe('sortValueNode', () => {
   });
 
   it('sort input object fields', () => {
-    expectSortedValue('{ b: 2, a: 1 }').to.equal('{a: 1, b: 2}');
-    expectSortedValue('{ a: { c: 3, b: 2 } }').to.equal('{a: {b: 2, c: 3}}');
-    expectSortedValue('[{ b: 2, a: 1 }, { d: 4, c: 3}]').to.equal(
-      '[{a: 1, b: 2}, {c: 3, d: 4}]',
+    expectSortedValue('{ b: 2, a: 1 }').to.equal('{ a: 1, b: 2 }');
+    expectSortedValue('{ a: { c: 3, b: 2 } }').to.equal(
+      '{ a: { b: 2, c: 3 } }',
+    );
+    expectSortedValue('[{ b: 2, a: 1 }, { d: 4, c: 3 }]').to.equal(
+      '[{ a: 1, b: 2 }, { c: 3, d: 4 }]',
     );
     expectSortedValue(
       '{ b: { g: 7, f: 6 }, c: 3 , a: { d: 4, e: 5 } }',
-    ).to.equal('{a: {d: 4, e: 5}, b: {f: 6, g: 7}, c: 3}');
+    ).to.equal('{ a: { d: 4, e: 5 }, b: { f: 6, g: 7 }, c: 3 }');
   });
 });