Skip to content

Commit

Permalink
Merge pull request #1117 from clement911/master
Browse files Browse the repository at this point in the history
Add non generic version of GraphService.SendAsync()
  • Loading branch information
clement911 authored Dec 10, 2024
2 parents 86a5c8d + 6567b0a commit e22fa35
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ShopifySharp/Services/Graph/GraphService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,20 @@ public virtual Task<TResult> SendAsync<TResult>(string graphqlQuery, int? graphq
/// <param name="cancellationToken"></param>
public virtual async Task<TResult> SendAsync<TResult>(GraphRequest request, int? graphqlQueryCost = null, CancellationToken cancellationToken = default)
where TResult : class
{
return (TResult)await SendAsync(request, typeof(TResult), graphqlQueryCost, cancellationToken);
}

public virtual Task<object> SendAsync(string graphqlQuery, Type resultType, int? graphqlQueryCost = null, CancellationToken cancellationToken = default)
{
return SendAsync(new GraphRequest { query = graphqlQuery }, resultType, graphqlQueryCost, cancellationToken);
}

public virtual async Task<object> SendAsync(GraphRequest request, Type resultType, int? graphqlQueryCost = null, CancellationToken cancellationToken = default)
{
var elt = await this.SendAsync(request, graphqlQueryCost, cancellationToken);
var ptyElt = elt.EnumerateObject().Single().Value;
return GraphQL.Serializer.Deserialize<TResult>(ptyElt.GetRawText());
return GraphQL.Serializer.Deserialize(ptyElt.GetRawText(), resultType);
}
#endif

Expand Down

0 comments on commit e22fa35

Please sign in to comment.