Skip to content

Commit 6ddb125

Browse files
andrew-humuCito
authored andcommitted
Implement __hash__ for GraphQLError (#35)
Make GraphQLError hashable
1 parent effaf2e commit 6ddb125

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

graphql/error/graphql_error.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ class GraphQLError(Exception):
8181
"extensions",
8282
)
8383

84+
__hash__ = Exception.__hash__
85+
8486
def __init__(
8587
self,
8688
message: str,
@@ -91,7 +93,7 @@ def __init__(
9193
original_error: Exception = None,
9294
extensions: Dict[str, Any] = None,
9395
) -> None:
94-
super(GraphQLError, self).__init__(message)
96+
super().__init__(message)
9597
self.message = message
9698
if nodes and not isinstance(nodes, list):
9799
nodes = [nodes] # type: ignore

tests/error/test_graphql_error.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,11 @@ def default_error_formatter_includes_extension_fields():
126126
"path": None,
127127
"extensions": {"foo": "bar"},
128128
}
129+
130+
def is_hashable():
131+
hash(GraphQLError("msg"))
132+
133+
def hashes_are_unique_per_instance():
134+
e1 = GraphQLError("msg")
135+
e2 = GraphQLError("msg")
136+
assert hash(e1) != hash(e2)

0 commit comments

Comments
 (0)