Skip to content

Commit 8410f78

Browse files
Deseralization errors
- Fix facet & autocomplete serialization error - Fix potential bug when build OrderBy
1 parent 338d007 commit 8410f78

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

APIs/src/EpiServer.ContentGraph/Api/Querying/GraphQueryBuilder.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public async Task<ContentGraphResult> GetResultAsync()
238238
/// </summary>
239239
/// <returns>string</returns>
240240
/// <exception cref="ServiceException"></exception>
241-
public async Task<string?> GetRawResultAsync()
241+
public async Task<string> GetRawResultAsync()
242242
{
243243
string url = GetServiceUrl();
244244

@@ -253,8 +253,7 @@ public async Task<ContentGraphResult> GetResultAsync()
253253
AdditionalInformation(jsonRequest, body);
254254
using (var reader = new StreamReader(await jsonRequest.GetResponseStream(body), jsonRequest.Encoding))
255255
{
256-
var jsonReader = new JsonTextReader(reader);
257-
return jsonReader.ReadAsString();
256+
return await reader.ReadToEndAsync();
258257
}
259258
}
260259
catch (AggregateException asyncException)

APIs/src/EpiServer.ContentGraph/Api/Querying/TypeQueryBuilder.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,11 @@ public override GraphQueryBuilder ToQuery()
582582
if (!graphObject.OrderBy.IsNullOrEmpty())
583583
{
584584
graphObject.OrderBy = $"orderBy:{{{graphObject.OrderBy}}}";
585+
graphObject.Filter = graphObject.Filter.IsNullOrEmpty() ? graphObject.OrderBy : $"{graphObject.Filter},{graphObject.OrderBy}";
585586
}
586-
if (!graphObject.Locale.IsNullOrEmpty() || !graphObject.Filter.IsNullOrEmpty() || !graphObject.WhereClause.IsNullOrEmpty() || !graphObject.OrderBy.IsNullOrEmpty())
587+
if (!graphObject.Locale.IsNullOrEmpty() || !graphObject.Filter.IsNullOrEmpty() || !graphObject.WhereClause.IsNullOrEmpty())
587588
{
588-
graphObject.Filter = $"({graphObject.Locale}{graphObject.Filter}{graphObject.WhereClause}{graphObject.OrderBy})";
589+
graphObject.Filter = $"({graphObject.Locale}{graphObject.Filter}{graphObject.WhereClause})";
589590
}
590591
if (!graphObject.Facets.IsNullOrEmpty())
591592
{

APIs/src/EpiServer.ContentGraph/Api/Result/ContentGraphHits.cs

+32-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public Dictionary<string, IEnumerable<Facet>> Facets
2727
facets = new Dictionary<string, IEnumerable<Facet>>();
2828
foreach (var key in keys)
2929
{
30-
facets.Add(key, RawFacets[key].ToObject<IEnumerable<Facet>>());
30+
GetJArray(RawFacets[key], key, facets);
3131
}
3232
}
3333
return facets;
@@ -48,19 +48,47 @@ public Dictionary<string, IEnumerable<string>> AutoComplete
4848
autocompletes = new Dictionary<string, IEnumerable<string>>();
4949
foreach (var key in keys)
5050
{
51-
autocompletes.Add(key, RawAutoComplete[key].ToObject<IEnumerable<string>>());
51+
GetJArray(RawAutoComplete[key], key, autocompletes);
5252
}
5353
}
5454
return autocompletes;
5555
}
5656
}
5757
[JsonProperty("facets")]
58-
private Dictionary<string, JArray> RawFacets { get; set; }
58+
private Dictionary<string, object> RawFacets { get; set; }
5959
[JsonProperty("autocomplete")]
60-
private Dictionary<string, JArray> RawAutoComplete { get; set; }
60+
private Dictionary<string, object> RawAutoComplete { get; set; }
6161
[JsonProperty("cursor")]
6262
public string Cursor { get; set; }
6363
[JsonProperty("total")]
6464
public int Total { get; set; }
65+
private void GetJArray<TReturn>(object jObject, string key, Dictionary<string, IEnumerable<TReturn>> keyValues)
66+
{
67+
switch (jObject.GetType().Name)
68+
{
69+
case "JObject":
70+
foreach (var token in ((JObject)jObject).Values())
71+
{
72+
string tempKey = key;
73+
if (token.GetType() == typeof(JArray))
74+
{
75+
tempKey = $"{tempKey}.{token.Path}";
76+
keyValues.Add(tempKey, ((JArray)token).ToObject<IEnumerable<TReturn>>());
77+
}
78+
else
79+
{
80+
GetJArray(token, tempKey, keyValues);
81+
}
82+
}
83+
break;
84+
case "JArray":
85+
keyValues.Add(key, ((JArray)jObject).ToObject<IEnumerable<TReturn>>());
86+
break;
87+
case "JProperty":
88+
break;
89+
default:
90+
break;
91+
}
92+
}
6593
}
6694
}

0 commit comments

Comments
 (0)