Skip to content

Add support for __str__ in ExecutionResult #274

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

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ docs/_build/
*.iml

# Visual Studio
/.vscode
.vscode/*

# OS X
.DS_Store
1 change: 0 additions & 1 deletion graphql/error/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def __init__(
self._locations = locations
self.path = path
self.extensions = extensions
return None

@property
def source(self):
Expand Down
3 changes: 3 additions & 0 deletions graphql/execution/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ def __eq__(self, other):
and self.invalid == other.invalid
)

def __str__(self):
return str(self.to_dict())

def to_dict(self, format_error=None, dict_class=OrderedDict):
# type: (Optional[Callable[[Exception], Dict]], Type[Dict]) -> Dict[str, Any]
if format_error is None:
Expand Down
16 changes: 9 additions & 7 deletions graphql/type/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ def is_same_type(self, other):
return self.__class__ is other.__class__ and self.name == other.name


def none_func(x):
None


class GraphQLScalarType(GraphQLNamedType):
"""Scalar Type Definition

Expand Down Expand Up @@ -144,6 +140,7 @@ def __init__(
# type: (...) -> None
assert name, "Type must be named."
assert_valid_name(name)
super(GraphQLScalarType, self).__init__(name)
self.name = name
self.description = description

Expand All @@ -161,8 +158,8 @@ def __init__(
)

self.serialize = serialize
self.parse_value = parse_value or none_func
self.parse_literal = parse_literal or none_func
self.parse_value = parse_value or None
self.parse_literal = parse_literal or None

def __str__(self):
# type: () -> str
Expand Down Expand Up @@ -207,6 +204,7 @@ def __init__(
# type: (...) -> None
assert name, "Type must be named."
assert_valid_name(name)
super(GraphQLObjectType, self).__init__(name)
self.name = name
self.description = description

Expand Down Expand Up @@ -341,7 +339,7 @@ class GraphQLArgument(object):

def __init__(
self,
type, # type: Union[GraphQLInputObjectType, GraphQLNonNull, GraphQLList, GraphQLScalarType]
type, # type: Union[GraphQLInputObjectType, GraphQLNonNull, GraphQLList, GraphQLScalarType, GraphQLEnumType]
default_value=None, # type: Optional[Any]
description=None, # type: Optional[Any]
out_name=None, # type: Optional[str]
Expand Down Expand Up @@ -388,6 +386,7 @@ def __init__(
description=None, # type: Optional[Any]
):
# type: (...) -> None
super(GraphQLInterfaceType, self).__init__(name)
assert name, "Type must be named."
assert_valid_name(name)
self.name = name
Expand Down Expand Up @@ -435,6 +434,7 @@ def __init__(
description=None, # type: Optional[Any]
):
# type: (...) -> None
super(GraphQLUnionType, self).__init__(name)
assert name, "Type must be named."
assert_valid_name(name)
self.name = name
Expand Down Expand Up @@ -510,6 +510,7 @@ class GraphQLEnumType(GraphQLNamedType):
def __init__(self, name, values, description=None):
assert name, "Type must provide name."
assert_valid_name(name)
super(GraphQLEnumType, self).__init__(name)
self.name = name
self.description = description

Expand Down Expand Up @@ -646,6 +647,7 @@ def __init__(
):
# type: (...) -> None
assert name, "Type must be named."
super(GraphQLInputObjectType, self).__init__(name)
self.name = name
self.description = description
if container_type is None:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def run_tests(self):
name="graphql-core",
version=version,
description="GraphQL implementation for Python",
long_description=open("README.md").read(),
long_description=open("README.md", encoding="utf8").read(),
long_description_content_type="text/markdown",
url="https://github.com/graphql-python/graphql-core-legacy",
download_url="https://github.com/graphql-python/graphql-core-legacy/releases",
Expand Down