Skip to content

Commit

Permalink
Merge pull request #936 from clement911/fix-graph-post2-with-leaky-po…
Browse files Browse the repository at this point in the history
…licy

Fixed bug when using GraphService.Post2 with LeakyBucket policy + add…
  • Loading branch information
clement911 authored Oct 5, 2023
2 parents 0ad9cee + d308414 commit c2a52cd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
30 changes: 20 additions & 10 deletions ShopifySharp.Tests/GenerateGraphQLSchema_Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,16 @@ public async Task GenerateGraphQLTypes()
[Fact]
public async Task GetOrders()
{
var res = await new GraphService(Utils.MyShopifyUrl, Utils.AccessToken).Post2Async(@"
foreach (var policy in new IRequestExecutionPolicy[]
{
new DefaultRequestExecutionPolicy(),
new RetryExecutionPolicy(),
new LeakyBucketExecutionPolicy()
})
{
var svc = new GraphService(Utils.MyShopifyUrl, Utils.AccessToken);
svc.SetExecutionPolicy(policy);
var res = await svc.Post2Async(@"
{
orders(first:10)
{
Expand All @@ -72,15 +81,16 @@ public async Task GetOrders()
}
}
");
var orders = res.GetProperty("orders").Deserialize<OrderConnection>();
Assert.True(orders.nodes.Length > 0);
var o = orders.nodes[0];
Assert.True(o.name != null);
Assert.True(o.lineItems.nodes.First().quantity != null);
var commentEventEmbed = o as ICommentEventEmbed;
Assert.NotNull(commentEventEmbed);
Assert.NotNull(commentEventEmbed.AsOrder());
Assert.Null(commentEventEmbed.AsCustomer());
var orders = res.GetProperty("orders").Deserialize<OrderConnection>();
Assert.True(orders.nodes.Length > 0);
var o = orders.nodes[0];
Assert.True(o.name != null);
Assert.True(o.lineItems.nodes.First().quantity != null);
var commentEventEmbed = o as ICommentEventEmbed;
Assert.NotNull(commentEventEmbed);
Assert.NotNull(commentEventEmbed.AsOrder());
Assert.Null(commentEventEmbed.AsCustomer());
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public async Task<RequestResult<T>> Run<T>(CloneableRequestMessage baseRequest,

var graphRes = await executeRequestAsync(request);
var json = graphRes.Result as JToken;
if (graphRes.Result is System.Text.Json.JsonDocument jsonDoc)
json = JToken.Parse(jsonDoc.RootElement.ToString());

if (bucket != null)
{
Expand Down

0 comments on commit c2a52cd

Please sign in to comment.