I am trying to call my GraphQL API using the generic HTTP client in .NET Core. The query doesn't work when I use the HTTP client. I have this set up in Bruno and get results back.
var queryObject = new
{
variables = new { },
query = $@"orders(take:1 skip:0 filter:""orderNumber == {orderUpdate.OrderNumber}"") {{
items {{
orderDate
orderNumber
items {{
itemNumber
}}
}}
}}"
};
var response = await m_Client.Post<GraphQLResult>(
m_GraphQlSettings.OrdersEndpoint,
bodyContent: JsonSerializer.Serialize(queryObject));
if(!response.Success)
{
m_Logger.LogError("GraphQL Errors");
return null;
}
My class:
public class GraphQLResult
{
public Order? Data { get; set; }
}
public class Order
{
public OrderHeader Orders { get; set; } = null!;
}
The API returns null and nothing gets run when the request has been sent so it has to do with the query.
doesn't seem to workdoesn't explain anything. EvenThe API returns a nullis unclear -responseis never null, even if an error is returned. The code you posted never checks the response contents in case of error.