0

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.

1
  • All HTTP calls use HttpClient underneath. If you use a library like Straweberry Shake, you're using HttpClient. doesn't seem to work doesn't explain anything. Even The API returns a null is unclear -response is never null, even if an error is returned. The code you posted never checks the response contents in case of error. Commented Nov 18 at 8:25

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.