Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix serialization of GraphQL responses #51

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading