Skip to content

Commit 7541f44

Browse files
committed
Update GraphQLError for Distinct call, fix text
1 parent e2d8a69 commit 7541f44

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

‎src/EntityGraphQL/QueryRequest.cs‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Linq;
23

34
namespace EntityGraphQL;
45

@@ -98,4 +99,35 @@ public GraphQLError(string message, string[]? path, IDictionary<string, object>?
9899
if (extensions != null)
99100
this[QueryResult.ExtensionsKey] = new Dictionary<string, object>(extensions);
100101
}
102+
103+
public override bool Equals(object? obj)
104+
{
105+
if (obj is not GraphQLError other)
106+
return false;
107+
108+
bool extensionsEqual =
109+
(Extensions == null && other.Extensions == null)
110+
|| (Extensions != null && other.Extensions != null && Extensions.Count == other.Extensions.Count && !Extensions.Except(other.Extensions).Any());
111+
112+
return Message == other.Message && ((Path == null && other.Path == null) || (Path != null && other.Path != null && Path.SequenceEqual(other.Path))) && extensionsEqual;
113+
}
114+
115+
public override int GetHashCode()
116+
{
117+
int hash = Message?.GetHashCode() ?? 0;
118+
if (Path != null)
119+
{
120+
foreach (var p in Path)
121+
hash = hash * 31 + (p?.GetHashCode() ?? 0);
122+
}
123+
if (Extensions != null)
124+
{
125+
foreach (var kv in Extensions.OrderBy(kv => kv.Key))
126+
{
127+
hash = hash * 31 + kv.Key.GetHashCode();
128+
hash = hash * 31 + (kv.Value?.GetHashCode() ?? 0);
129+
}
130+
}
131+
return hash;
132+
}
101133
}

0 commit comments

Comments
 (0)