Skip to content

Commit fedea86

Browse files
committed
test: add tests for printing QueryBuilder in GraphQL syntax
1 parent 001f75e commit fedea86

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

gqlrequests/builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __str__(cls):
4343
output = f"type {cls.__name__} {{\n"
4444
for key, value in cls._resolved_fields.items():
4545
output += f" {key}: {value.__name__}\n"
46-
output += "}"
46+
output += "}\n"
4747
return output
4848

4949
class QueryBuilder(metaclass=QueryBuilderMeta):

tests/test_creating_builder.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,38 @@ class InvalidType(gqlrequests.QueryBuilder):
8484

8585
def test_invalid_type_throws_value_error():
8686
with pytest.raises(ValueError) as e:
87-
InvalidType().build()
87+
InvalidType().build()
88+
89+
90+
def test_string_representation_of_class_shows_graphql_syntax():
91+
class EveryType(gqlrequests.QueryBuilder):
92+
id: int
93+
age: int
94+
money: float
95+
name: str
96+
company: bool
97+
98+
correct_string = """
99+
type EveryType {
100+
id: int
101+
age: int
102+
money: float
103+
name: str
104+
company: bool
105+
}
106+
"""[1:]
107+
assert str(EveryType) == correct_string
108+
109+
def test_string_representation_of_nested_class_shows_graphql_syntax():
110+
correct_string = """
111+
type NestedType {
112+
something: SomethingType
113+
}
114+
"""[1:]
115+
class SomethingType(gqlrequests.QueryBuilder):
116+
id: int
117+
118+
class NestedType(gqlrequests.QueryBuilder):
119+
something: SomethingType
120+
121+
assert str(NestedType) == correct_string

0 commit comments

Comments
 (0)