Skip to content

Commit b52a240

Browse files
committed
print: add spaces inside input object
Replicates graphql/graphql-js@5ccf579
1 parent f8b11c2 commit b52a240

File tree

9 files changed

+26
-24
lines changed

9 files changed

+26
-24
lines changed

src/graphql/language/printer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def leave_list_value(node: PrintedNode, *_args: Any) -> str:
169169

170170
@staticmethod
171171
def leave_object_value(node: PrintedNode, *_args: Any) -> str:
172-
return f"{{{join(node.fields, ', ')}}}"
172+
return f"{{ {join(node.fields, ', ')} }}"
173173

174174
@staticmethod
175175
def leave_object_field(node: PrintedNode, *_args: Any) -> str:

tests/language/test_printer.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ def correctly_prints_mutation_operation_with_artifacts():
6060

6161
def prints_query_with_variable_directives():
6262
query_ast_with_variable_directive = parse(
63-
"query ($foo: TestType = {a: 123}" " @testDirective(if: true) @test) { id }"
63+
"query ($foo: TestType = { a: 123 }"
64+
" @testDirective(if: true) @test) { id }"
6465
)
6566
assert print_ast(query_ast_with_variable_directive) == dedent(
6667
"""
67-
query ($foo: TestType = {a: 123} @testDirective(if: true) @test) {
68+
query ($foo: TestType = { a: 123 } @testDirective(if: true) @test) {
6869
id
6970
}
7071
"""
@@ -185,9 +186,9 @@ def prints_kitchen_sink_without_altering_ast(kitchen_sink_query): # noqa: F811
185186
foo(
186187
size: $size
187188
bar: $b
188-
obj: {key: "value", block: """
189+
obj: { key: "value", block: """
189190
block string uses \"""
190-
"""}
191+
""" }
191192
)
192193
}
193194

tests/language/test_schema_printer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def prints_kitchen_sink_without_altering_ast(kitchen_sink_sdl): # noqa: F811
5656
three(argument: InputType, other: String): Int
5757
four(argument: String = "string"): String
5858
five(argument: [String] = ["string", "string"]): String
59-
six(argument: InputType = {key: "value"}): Type
59+
six(argument: InputType = { key: "value" }): Type
6060
seven(argument: Int = null): Type
6161
}
6262

tests/type/test_custom_scalars.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def parse_literal():
186186
def parse_literal_with_errors():
187187
source = """
188188
query Money($amount: String!, $currency: Float!) {
189-
toEuros(money: {amount: $amount, currency: $currency})
189+
toEuros(money: { amount: $amount, currency: $currency })
190190
}
191191
"""
192192

@@ -197,7 +197,7 @@ def parse_literal_with_errors():
197197
[
198198
{
199199
"message": "Argument 'money' has invalid value"
200-
" {amount: $amount, currency: $currency}.",
200+
" { amount: $amount, currency: $currency }.",
201201
"locations": [(3, 30)],
202202
},
203203
],

tests/type/test_introspection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ def introspects_any_default_value():
10791079
"""
10801080
input InputObjectWithDefaultValues {
10811081
a: String = "Emoji: \\u{1F600}"
1082-
b: Complex = {x: ["abc"], y: 123}
1082+
b: Complex = { x: ["abc"], y: 123 }
10831083
}
10841084
10851085
input Complex {
@@ -1109,7 +1109,7 @@ def introspects_any_default_value():
11091109
"__type": {
11101110
"inputFields": [
11111111
{"name": "a", "defaultValue": '"Emoji: \U0001f600"'},
1112-
{"name": "b", "defaultValue": '{x: ["abc"], y: 123}'},
1112+
{"name": "b", "defaultValue": '{ x: ["abc"], y: 123 }'},
11131113
]
11141114
}
11151115
},

tests/type/test_scalars.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def _parse_literal_raises(s: str, message: str):
9393
)
9494
_parse_literal_raises("[1]", "Int cannot represent non-integer value: [1]")
9595
_parse_literal_raises(
96-
"{value: 1}", "Int cannot represent non-integer value: {value: 1}"
96+
"{value: 1}", "Int cannot represent non-integer value: { value: 1 }"
9797
)
9898
_parse_literal_raises(
9999
"ENUM_VALUE", "Int cannot represent non-integer value: ENUM_VALUE"
@@ -246,7 +246,8 @@ def _parse_literal_raises(s: str, message: str):
246246
"[0.1]", "Float cannot represent non numeric value: [0.1]"
247247
)
248248
_parse_literal_raises(
249-
"{value: 0.1}", "Float cannot represent non numeric value: {value: 0.1}"
249+
"{value: 0.1}",
250+
"Float cannot represent non numeric value: { value: 0.1 }",
250251
)
251252
_parse_literal_raises(
252253
"ENUM_VALUE", "Float cannot represent non numeric value: ENUM_VALUE"
@@ -357,7 +358,7 @@ def _parse_literal_raises(s: str, message: str):
357358
)
358359
_parse_literal_raises(
359360
'{value: "foo"}',
360-
'String cannot represent a non string value: {value: "foo"}',
361+
'String cannot represent a non string value: { value: "foo" }',
361362
)
362363
_parse_literal_raises(
363364
"ENUM_VALUE", "String cannot represent a non string value: ENUM_VALUE"
@@ -488,11 +489,11 @@ def _parse_literal_raises(s: str, message: str):
488489
)
489490
_parse_literal_raises(
490491
"{value: false}",
491-
"Boolean cannot represent a non boolean value: {value: false}",
492+
"Boolean cannot represent a non boolean value: { value: false }",
492493
)
493494
_parse_literal_raises(
494495
"{value: False}",
495-
"Boolean cannot represent a non boolean value: {value: False}",
496+
"Boolean cannot represent a non boolean value: { value: False }",
496497
)
497498
_parse_literal_raises(
498499
"ENUM_VALUE", "Boolean cannot represent a non boolean value: ENUM_VALUE"
@@ -614,9 +615,9 @@ def _parse_literal_raises(s: str, message: str):
614615
'["1"]', 'ID cannot represent a non-string and non-integer value: ["1"]'
615616
)
616617
_parse_literal_raises(
617-
'{value: "1"}',
618+
'{ value: "1" }',
618619
"ID cannot represent a non-string and non-integer value:"
619-
' {value: "1"}',
620+
' { value: "1" }',
620621
)
621622
_parse_literal_raises(
622623
"ENUM_VALUE",

tests/utilities/test_build_client_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ def builds_a_schema_with_field_arguments_with_default_values():
459459
type Query {
460460
defaultInt(intArg: Int = 30): String
461461
defaultList(listArg: [Int] = [1, 2, 3]): String
462-
defaultObject(objArg: Geo = {lat: 37.485, lon: -122.148}): String
462+
defaultObject(objArg: Geo = { lat: 37.485, lon: -122.148 }): String
463463
defaultNull(intArg: Int = null): String
464464
noDefault(intArg: Int): String
465465
}

tests/utilities/test_find_breaking_changes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,8 +986,8 @@ def should_detect_if_a_default_value_changed_on_an_argument():
986986
(
987987
DangerousChangeType.ARG_DEFAULT_VALUE_CHANGE,
988988
"Type1.field1 arg complexObject has changed defaultValue"
989-
" from {innerInputArray: [{arrayField: [1, 2, 3]}]}"
990-
" to {innerInputArray: [{arrayField: [3, 2, 1]}]}.",
989+
" from { innerInputArray: [{ arrayField: [1, 2, 3] }] }"
990+
" to { innerInputArray: [{ arrayField: [3, 2, 1] }] }.",
991991
),
992992
]
993993

tests/utilities/test_sort_value_node.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ def do_not_change_non_object_values():
2121
)
2222

2323
def sort_input_object_fields():
24-
_expect_sorted_value("{ b: 2, a: 1 }", "{a: 1, b: 2}")
25-
_expect_sorted_value("{ a: { c: 3, b: 2 } }", "{a: {b: 2, c: 3}}")
24+
_expect_sorted_value("{ b: 2, a: 1 }", "{ a: 1, b: 2 }")
25+
_expect_sorted_value("{ a: { c: 3, b: 2 } }", "{ a: { b: 2, c: 3 } }")
2626
_expect_sorted_value(
2727
"[{ b: 2, a: 1 }, { d: 4, c: 3}]",
28-
"[{a: 1, b: 2}, {c: 3, d: 4}]",
28+
"[{ a: 1, b: 2 }, { c: 3, d: 4 }]",
2929
)
3030
_expect_sorted_value(
3131
"{ b: { g: 7, f: 6 }, c: 3 , a: { d: 4, e: 5 } }",
32-
"{a: {d: 4, e: 5}, b: {f: 6, g: 7}, c: 3}",
32+
"{ a: { d: 4, e: 5 }, b: { f: 6, g: 7 }, c: 3 }",
3333
)

0 commit comments

Comments
 (0)