Skip to content

Commit

Permalink
Implement __hash__ for GraphQLError (#35)
Browse files Browse the repository at this point in the history
Make GraphQLError hashable
  • Loading branch information
andrew-humu authored and Cito committed May 31, 2019
1 parent effaf2e commit 6ddb125
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion graphql/error/graphql_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class GraphQLError(Exception):
"extensions",
)

__hash__ = Exception.__hash__

def __init__(
self,
message: str,
Expand All @@ -91,7 +93,7 @@ def __init__(
original_error: Exception = None,
extensions: Dict[str, Any] = None,
) -> None:
super(GraphQLError, self).__init__(message)
super().__init__(message)
self.message = message
if nodes and not isinstance(nodes, list):
nodes = [nodes] # type: ignore
Expand Down
8 changes: 8 additions & 0 deletions tests/error/test_graphql_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,11 @@ def default_error_formatter_includes_extension_fields():
"path": None,
"extensions": {"foo": "bar"},
}

def is_hashable():
hash(GraphQLError("msg"))

def hashes_are_unique_per_instance():
e1 = GraphQLError("msg")
e2 = GraphQLError("msg")
assert hash(e1) != hash(e2)

0 comments on commit 6ddb125

Please sign in to comment.