From 151e733342f78bf1ba2a4cc3007eac2a04f615e5 Mon Sep 17 00:00:00 2001 From: Steve Bjorg Date: Tue, 6 Oct 2020 13:44:58 -0700 Subject: [PATCH 1/4] preserve all entries in GraphQLRequest --- src/GraphQL.Client/GraphQLHttpRequest.cs | 2 +- src/GraphQL.Primitives/GraphQLRequest.cs | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/GraphQL.Client/GraphQLHttpRequest.cs b/src/GraphQL.Client/GraphQLHttpRequest.cs index 00f90d4a..eb3aac14 100644 --- a/src/GraphQL.Client/GraphQLHttpRequest.cs +++ b/src/GraphQL.Client/GraphQLHttpRequest.cs @@ -16,7 +16,7 @@ public GraphQLHttpRequest(string query, object? variables = null, string? operat { } - public GraphQLHttpRequest(GraphQLRequest other): base(other.Query, other.Variables, other.OperationName) + public GraphQLHttpRequest(GraphQLRequest other): base(other) { } diff --git a/src/GraphQL.Primitives/GraphQLRequest.cs b/src/GraphQL.Primitives/GraphQLRequest.cs index 72033552..19c7fded 100644 --- a/src/GraphQL.Primitives/GraphQLRequest.cs +++ b/src/GraphQL.Primitives/GraphQLRequest.cs @@ -49,6 +49,14 @@ public GraphQLRequest(string query, object? variables = null, string? operationN OperationName = operationName; } + public GraphQLRequest(IEnumerable> values) + { + foreach(var kv in values) + { + Add(kv.Key, kv.Value); + } + } + /// /// Returns a value that indicates whether this instance is equal to a specified object /// @@ -86,7 +94,7 @@ public override int GetHashCode() { unchecked { - var hashCode = Query.GetHashCode(); + var hashCode = Query?.GetHashCode() ?? 0; hashCode = (hashCode * 397) ^ OperationName?.GetHashCode() ?? 0; hashCode = (hashCode * 397) ^ Variables?.GetHashCode() ?? 0; return hashCode; From 840da16ec92416bc34a495942d2f396695894408 Mon Sep 17 00:00:00 2001 From: Steve Bjorg Date: Tue, 6 Oct 2020 14:53:31 -0700 Subject: [PATCH 2/4] make copy constructor more specific --- src/GraphQL.Primitives/GraphQLRequest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/GraphQL.Primitives/GraphQLRequest.cs b/src/GraphQL.Primitives/GraphQLRequest.cs index 19c7fded..22074321 100644 --- a/src/GraphQL.Primitives/GraphQLRequest.cs +++ b/src/GraphQL.Primitives/GraphQLRequest.cs @@ -49,9 +49,9 @@ public GraphQLRequest(string query, object? variables = null, string? operationN OperationName = operationName; } - public GraphQLRequest(IEnumerable> values) + public GraphQLRequest(GraphQLRequest other) { - foreach(var kv in values) + foreach(var kv in other) { Add(kv.Key, kv.Value); } From 2dd397d20dd0de60fbddceba6f59dbefbeb98d37 Mon Sep 17 00:00:00 2001 From: Alexander Rose Date: Thu, 15 Oct 2020 10:02:00 +0200 Subject: [PATCH 3/4] use Dictionary copy constructor on new GraphQLRequest constructor --- src/GraphQL.Primitives/GraphQLRequest.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/GraphQL.Primitives/GraphQLRequest.cs b/src/GraphQL.Primitives/GraphQLRequest.cs index 22074321..7e0c2dea 100644 --- a/src/GraphQL.Primitives/GraphQLRequest.cs +++ b/src/GraphQL.Primitives/GraphQLRequest.cs @@ -49,13 +49,7 @@ public GraphQLRequest(string query, object? variables = null, string? operationN OperationName = operationName; } - public GraphQLRequest(GraphQLRequest other) - { - foreach(var kv in other) - { - Add(kv.Key, kv.Value); - } - } + public GraphQLRequest(GraphQLRequest other): base(other) { } /// /// Returns a value that indicates whether this instance is equal to a specified object From 15f10451437dde34bb6b7f98f0cf5069d2d75f56 Mon Sep 17 00:00:00 2001 From: Alexander Rose Date: Thu, 15 Oct 2020 10:03:02 +0200 Subject: [PATCH 4/4] fix GraphQLRequest.GetHastCode() --- src/GraphQL.Primitives/GraphQLRequest.cs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/GraphQL.Primitives/GraphQLRequest.cs b/src/GraphQL.Primitives/GraphQLRequest.cs index 7e0c2dea..d471077f 100644 --- a/src/GraphQL.Primitives/GraphQLRequest.cs +++ b/src/GraphQL.Primitives/GraphQLRequest.cs @@ -84,16 +84,7 @@ public virtual bool Equals(GraphQLRequest? other) /// /// /// - public override int GetHashCode() - { - unchecked - { - var hashCode = Query?.GetHashCode() ?? 0; - hashCode = (hashCode * 397) ^ OperationName?.GetHashCode() ?? 0; - hashCode = (hashCode * 397) ^ Variables?.GetHashCode() ?? 0; - return hashCode; - } - } + public override int GetHashCode() => (Query, OperationName, Variables).GetHashCode(); /// /// Tests whether two specified instances are equivalent