Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

👽 Use .formatted instead of format_error #1327

Merged
merged 2 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,7 @@ def test_array_field_filter_schema_type(Query):
"randomField": "[Boolean!]",
}
filters_str = ", ".join(
[
f"{filter_field}: {gql_type} = null"
for filter_field, gql_type in filters.items()
]
[f"{filter_field}: {gql_type}" for filter_field, gql_type in filters.items()]
)
assert (
f"type Query {{\n events({filters_str}): EventTypeConnection\n}}" in schema_str
Expand Down
5 changes: 1 addition & 4 deletions graphene_django/filter/tests/test_enum_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ def test_filter_enum_field_schema_type(schema):
"reporter_AChoice_In": "[TestsReporterAChoiceChoices]",
}
filters_str = ", ".join(
[
f"{filter_field}: {gql_type} = null"
for filter_field, gql_type in filters.items()
]
[f"{filter_field}: {gql_type}" for filter_field, gql_type in filters.items()]
)
assert f" allArticles({filters_str}): ArticleTypeConnection\n" in schema_str
10 changes: 4 additions & 6 deletions graphene_django/filter/tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ class Query(ObjectType):
assert str(schema) == dedent(
"""\
type Query {
pets(offset: Int = null, before: String = null, after: String = null, first: Int = null, last: Int = null, age: Int = null): PetTypeConnection
pets(offset: Int, before: String, after: String, first: Int, last: Int, age: Int): PetTypeConnection
}
type PetTypeConnection {
Expand Down Expand Up @@ -1056,8 +1056,7 @@ class Query(ObjectType):
interface Node {
\"""The ID of the object\"""
id: ID!
}
"""
}"""
)


Expand All @@ -1077,7 +1076,7 @@ class Query(ObjectType):
assert str(schema) == dedent(
"""\
type Query {
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
pets(offset: Int, before: String, after: String, first: Int, last: Int, age: Int, age_Isnull: Boolean, age_Lt: Int): PetTypeConnection
}
type PetTypeConnection {
Expand Down Expand Up @@ -1125,8 +1124,7 @@ class Query(ObjectType):
interface Node {
\"""The ID of the object\"""
id: ID!
}
"""
}"""
)


Expand Down
2 changes: 1 addition & 1 deletion graphene_django/filter/tests/test_typed_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_typed_filter_schema(schema):
)

for filter_field, gql_type in filters.items():
assert "{}: {} = null".format(filter_field, gql_type) in all_articles_filters
assert "{}: {}".format(filter_field, gql_type) in all_articles_filters


def test_typed_filters_work(schema):
Expand Down
3 changes: 1 addition & 2 deletions graphene_django/tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,5 @@ class Query(ObjectType):
"""\
type Query {
hi: String
}
"""
}"""
)
20 changes: 7 additions & 13 deletions graphene_django/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_schema_representation():
pets: [Reporter!]!
aChoice: TestsReporterAChoiceChoices
reporterType: TestsReporterReporterTypeChoices
articles(offset: Int = null, before: String = null, after: String = null, first: Int = null, last: Int = null): ArticleConnection!
articles(offset: Int, before: String, after: String, first: Int, last: Int): ArticleConnection!
}
\"""An enumeration.\"""
Expand Down Expand Up @@ -244,8 +244,7 @@ def test_schema_representation():
\"""The ID of the object\"""
id: ID!
): Node
}
"""
}"""
)
assert str(schema) == expected

Expand Down Expand Up @@ -525,8 +524,7 @@ class Query(ObjectType):
id: ID!
kind: String!
cuteness: Int!
}
"""
}"""
)

def test_django_objecttype_convert_choices_enum_list(self, PetModel):
Expand Down Expand Up @@ -560,8 +558,7 @@ class Query(ObjectType):
\"""Dog\"""
DOG
}
"""
}"""
)

def test_django_objecttype_convert_choices_enum_empty_list(self, PetModel):
Expand All @@ -586,8 +583,7 @@ class Query(ObjectType):
id: ID!
kind: String!
cuteness: Int!
}
"""
}"""
)

def test_django_objecttype_convert_choices_enum_naming_collisions(
Expand Down Expand Up @@ -621,8 +617,7 @@ class Query(ObjectType):
\"""Dog\"""
DOG
}
"""
}"""
)

def test_django_objecttype_choices_custom_enum_name(
Expand Down Expand Up @@ -660,8 +655,7 @@ class Query(ObjectType):
\"""Dog\"""
DOG
}
"""
}"""
)


Expand Down
5 changes: 0 additions & 5 deletions graphene_django/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,10 @@ def test_reports_validation_errors(client):
{
"message": "Cannot query field 'unknownOne' on type 'QueryRoot'.",
"locations": [{"line": 1, "column": 9}],
"path": None,
},
{
"message": "Cannot query field 'unknownTwo' on type 'QueryRoot'.",
"locations": [{"line": 1, "column": 21}],
"path": None,
},
]
}
Expand All @@ -135,8 +133,6 @@ def test_errors_when_missing_operation_name(client):
"errors": [
{
"message": "Must provide operation name if query contains multiple operations.",
"locations": None,
"path": None,
}
]
}
Expand Down Expand Up @@ -477,7 +473,6 @@ def test_handles_syntax_errors_caught_by_graphql(client):
{
"locations": [{"column": 1, "line": 1}],
"message": "Syntax Error: Unexpected Name 'syntaxerror'.",
"path": None,
}
]
}
Expand Down
3 changes: 1 addition & 2 deletions graphene_django/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from django.views.generic import View
from graphql import OperationType, get_operation_ast, parse, validate
from graphql.error import GraphQLError
from graphql.error import format_error as format_graphql_error
from graphql.execution import ExecutionResult

from graphene import Schema
Expand Down Expand Up @@ -387,7 +386,7 @@ def get_graphql_params(request, data):
@staticmethod
def format_error(error):
if isinstance(error, GraphQLError):
return format_graphql_error(error)
return error.formatted

return {"message": str(error)}

Expand Down