Skip to content

Commit 5f1731d

Browse files
authored
Fix: Use .formatted instead of format_error (#1327) & Fix tests
* 👽 Use .formatted instead of format_error * ✅ Fix test with newer graphene null default values (graphql-python/graphene@03277a5) no more trailing newlines
1 parent f6ec068 commit 5f1731d

8 files changed

+16
-37
lines changed

graphene_django/filter/tests/test_array_field_exact_filter.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,7 @@ def test_array_field_filter_schema_type(Query):
120120
"randomField": "[Boolean!]",
121121
}
122122
filters_str = ", ".join(
123-
[
124-
f"{filter_field}: {gql_type} = null"
125-
for filter_field, gql_type in filters.items()
126-
]
123+
[f"{filter_field}: {gql_type}" for filter_field, gql_type in filters.items()]
127124
)
128125
assert (
129126
f"type Query {{\n events({filters_str}): EventTypeConnection\n}}" in schema_str

graphene_django/filter/tests/test_enum_filtering.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,6 @@ def test_filter_enum_field_schema_type(schema):
152152
"reporter_AChoice_In": "[TestsReporterAChoiceChoices]",
153153
}
154154
filters_str = ", ".join(
155-
[
156-
f"{filter_field}: {gql_type} = null"
157-
for filter_field, gql_type in filters.items()
158-
]
155+
[f"{filter_field}: {gql_type}" for filter_field, gql_type in filters.items()]
159156
)
160157
assert f" allArticles({filters_str}): ArticleTypeConnection\n" in schema_str

graphene_django/filter/tests/test_fields.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ class Query(ObjectType):
10081008
assert str(schema) == dedent(
10091009
"""\
10101010
type Query {
1011-
pets(offset: Int = null, before: String = null, after: String = null, first: Int = null, last: Int = null, age: Int = null): PetTypeConnection
1011+
pets(offset: Int, before: String, after: String, first: Int, last: Int, age: Int): PetTypeConnection
10121012
}
10131013
10141014
type PetTypeConnection {
@@ -1056,8 +1056,7 @@ class Query(ObjectType):
10561056
interface Node {
10571057
\"""The ID of the object\"""
10581058
id: ID!
1059-
}
1060-
"""
1059+
}"""
10611060
)
10621061

10631062

@@ -1077,7 +1076,7 @@ class Query(ObjectType):
10771076
assert str(schema) == dedent(
10781077
"""\
10791078
type Query {
1080-
pets(offset: Int = null, before: String = null, after: String = null, first: Int = null, last: Int = null, age: Int = null, age_Isnull: Boolean = null, age_Lt: Int = null): PetTypeConnection
1079+
pets(offset: Int, before: String, after: String, first: Int, last: Int, age: Int, age_Isnull: Boolean, age_Lt: Int): PetTypeConnection
10811080
}
10821081
10831082
type PetTypeConnection {
@@ -1125,8 +1124,7 @@ class Query(ObjectType):
11251124
interface Node {
11261125
\"""The ID of the object\"""
11271126
id: ID!
1128-
}
1129-
"""
1127+
}"""
11301128
)
11311129

11321130

graphene_django/filter/tests/test_typed_filter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def test_typed_filter_schema(schema):
9898
)
9999

100100
for filter_field, gql_type in filters.items():
101-
assert "{}: {} = null".format(filter_field, gql_type) in all_articles_filters
101+
assert "{}: {}".format(filter_field, gql_type) in all_articles_filters
102102

103103

104104
def test_typed_filters_work(schema):

graphene_django/tests/test_command.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,5 @@ class Query(ObjectType):
5353
"""\
5454
type Query {
5555
hi: String
56-
}
57-
"""
56+
}"""
5857
)

graphene_django/tests/test_types.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def test_schema_representation():
183183
pets: [Reporter!]!
184184
aChoice: TestsReporterAChoiceChoices
185185
reporterType: TestsReporterReporterTypeChoices
186-
articles(offset: Int = null, before: String = null, after: String = null, first: Int = null, last: Int = null): ArticleConnection!
186+
articles(offset: Int, before: String, after: String, first: Int, last: Int): ArticleConnection!
187187
}
188188
189189
\"""An enumeration.\"""
@@ -244,8 +244,7 @@ def test_schema_representation():
244244
\"""The ID of the object\"""
245245
id: ID!
246246
): Node
247-
}
248-
"""
247+
}"""
249248
)
250249
assert str(schema) == expected
251250

@@ -525,8 +524,7 @@ class Query(ObjectType):
525524
id: ID!
526525
kind: String!
527526
cuteness: Int!
528-
}
529-
"""
527+
}"""
530528
)
531529

532530
def test_django_objecttype_convert_choices_enum_list(self, PetModel):
@@ -560,8 +558,7 @@ class Query(ObjectType):
560558
561559
\"""Dog\"""
562560
DOG
563-
}
564-
"""
561+
}"""
565562
)
566563

567564
def test_django_objecttype_convert_choices_enum_empty_list(self, PetModel):
@@ -586,8 +583,7 @@ class Query(ObjectType):
586583
id: ID!
587584
kind: String!
588585
cuteness: Int!
589-
}
590-
"""
586+
}"""
591587
)
592588

593589
def test_django_objecttype_convert_choices_enum_naming_collisions(
@@ -621,8 +617,7 @@ class Query(ObjectType):
621617
622618
\"""Dog\"""
623619
DOG
624-
}
625-
"""
620+
}"""
626621
)
627622

628623
def test_django_objecttype_choices_custom_enum_name(
@@ -660,8 +655,7 @@ class Query(ObjectType):
660655
661656
\"""Dog\"""
662657
DOG
663-
}
664-
"""
658+
}"""
665659
)
666660

667661

graphene_django/tests/test_views.py

-5
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,10 @@ def test_reports_validation_errors(client):
109109
{
110110
"message": "Cannot query field 'unknownOne' on type 'QueryRoot'.",
111111
"locations": [{"line": 1, "column": 9}],
112-
"path": None,
113112
},
114113
{
115114
"message": "Cannot query field 'unknownTwo' on type 'QueryRoot'.",
116115
"locations": [{"line": 1, "column": 21}],
117-
"path": None,
118116
},
119117
]
120118
}
@@ -135,8 +133,6 @@ def test_errors_when_missing_operation_name(client):
135133
"errors": [
136134
{
137135
"message": "Must provide operation name if query contains multiple operations.",
138-
"locations": None,
139-
"path": None,
140136
}
141137
]
142138
}
@@ -477,7 +473,6 @@ def test_handles_syntax_errors_caught_by_graphql(client):
477473
{
478474
"locations": [{"column": 1, "line": 1}],
479475
"message": "Syntax Error: Unexpected Name 'syntaxerror'.",
480-
"path": None,
481476
}
482477
]
483478
}

graphene_django/views.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from django.views.generic import View
1212
from graphql import OperationType, get_operation_ast, parse, validate
1313
from graphql.error import GraphQLError
14-
from graphql.error import format_error as format_graphql_error
1514
from graphql.execution import ExecutionResult
1615

1716
from graphene import Schema
@@ -387,7 +386,7 @@ def get_graphql_params(request, data):
387386
@staticmethod
388387
def format_error(error):
389388
if isinstance(error, GraphQLError):
390-
return format_graphql_error(error)
389+
return error.formatted
391390

392391
return {"message": str(error)}
393392

0 commit comments

Comments
 (0)