I think this is a general rule with the querybuilders that implement IQuery but not IGraphOperationQueryBuilder ... at least it is with the ones I am using (ProductQueryBuilder & ProductVariantQueryBuilder):
After generating the query text with query.Build(), this cannot be applied as-is to the Query property of a GraphRequest. If you do you get an "unexpected identifier" error response from the API.
What you have to do is wrap the query text inside
query { ... query text ... }
as in the following code:
public static T Execute<T>(this IQuery query, GraphService service)
{
var queryText = query.Build();
var request = new GraphRequest()
{
Query = $"query {{ {queryText} }}",
UserErrorHandling = ShopifySharp.Services.Graph.GraphRequestUserErrorHandling.Throw
};
var result = service.PostAsync<T>(request).Result.Data;
return result;
}
I think this is a general rule with the querybuilders that implement IQuery but not IGraphOperationQueryBuilder ... at least it is with the ones I am using (ProductQueryBuilder & ProductVariantQueryBuilder):
After generating the query text with query.Build(), this cannot be applied as-is to the Query property of a GraphRequest. If you do you get an "unexpected identifier" error response from the API.
What you have to do is wrap the query text inside
as in the following code: