From cc7020e4a0ff88d1dc056e40374fe75e74d5be97 Mon Sep 17 00:00:00 2001 From: evcheng-rubrik <97479644+evcheng-rubrik@users.noreply.github.com> Date: Thu, 14 Mar 2024 16:55:22 -0700 Subject: [PATCH] Fix serialization of GraphQL responses (#51) * Fix serialization of GraphQL responses * Trigger CI --- CHANGELOG.md | 4 +++ .../GraphQLClient.cs | 34 ------------------- 2 files changed, 4 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c62cb547d..1e431b1f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ Fixes: +- Fixed an issue in which certain GraphQL calls responded with + `Unable to cast object of type 'Newtonsoft.Json.Linq.JValue' + to type 'Newtonsoft.Json.Linq.JObject'.` + New Features: Breaking Changes: diff --git a/RubrikSecurityCloud/RubrikSecurityCloud.Client/GraphQLClient.cs b/RubrikSecurityCloud/RubrikSecurityCloud.Client/GraphQLClient.cs index e4346bda0..3db48dcdd 100644 --- a/RubrikSecurityCloud/RubrikSecurityCloud.Client/GraphQLClient.cs +++ b/RubrikSecurityCloud/RubrikSecurityCloud.Client/GraphQLClient.cs @@ -310,43 +310,9 @@ private async Task InvokeGraphQLQuery( throw new System.Net.Http.HttpRequestException(msg); } - JObject reply = response.Data as JObject; - RenameInterfaceFields(reply); return response.Data; } - private void RenameInterfaceFields(JObject replyObject) - { - const string interfaceFieldId = "_INTERFACE_FIELD_"; - foreach (JProperty field in replyObject.Properties().ToList()) - { - if (field.Name.Contains(interfaceFieldId)) - { - string fieldname = field.Name - .Split( - new[] { interfaceFieldId }, - StringSplitOptions.RemoveEmptyEntries - ) - .Last(); - JProperty newField = - new JProperty(fieldname, field.Value); - field.Replace(newField); - } - - if (field.Value.Type == JTokenType.Object) - { - RenameInterfaceFields(field.Value as JObject); - } - else if (field.Value.Type == JTokenType.Array) - { - foreach (JObject subfield in field.Value) - { - RenameInterfaceFields(subfield); - } - } - } - } - private string GraphQLRequestToString(GraphQLRequest request) { if (request == null)