Skip to content

Commit

Permalink
Fix serialization of GraphQL responses (#51)
Browse files Browse the repository at this point in the history
* Fix serialization of GraphQL responses

* Trigger CI
  • Loading branch information
evcheng-rubrik authored Mar 14, 2024
1 parent 55225f3 commit cc7020e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 34 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
34 changes: 0 additions & 34 deletions RubrikSecurityCloud/RubrikSecurityCloud.Client/GraphQLClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,43 +310,9 @@ private async Task<T> InvokeGraphQLQuery<T>(
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)
Expand Down

0 comments on commit cc7020e

Please sign in to comment.