A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I'm trying to write some vb.net code to call Graphql using httpclient (the postasync call).
This example works:
Dim body As String = "{""query"": ""{shop {name} }""}"
as does:
Dim body As String = "{""query"": ""{products(first: 3) {edges {node {id title} } } }""}"
but I'm struggling with the syntax for extending the set of products return to those which match a product_type, so this:
Dim body As String = "{""query"": ""{products(first: 3, query:""product_type:Fabric"") {edges {node {id title} } } }""}"
returns "Bad Request"
the string is being encoded as:
Dim content = New StringContent(body, Encoding.UTF8, "application/json")
and called as:
Dim response = request.PostAsync(url, content).Result
Any pointers most welcome.
Solved! Go to the solution
This is an accepted solution.
I eventually worked it out and posting here in case it helps someone in the future. The answer was to escape the double quotes in the middle query so this works:
Dim body As String = "{""query"": ""{products(first: 3, query:\""product_type:Fabric\"") {edges {node {id title} } } }""}"
Dim body As String = "{""query"": ""{products(first: 3, query:""product_type:Fabric"") {edges {node {id title} } } }""}" this word in red also shoud be quoted
please ignore the reply. It is not right
This is an accepted solution.
I eventually worked it out and posting here in case it helps someone in the future. The answer was to escape the double quotes in the middle query so this works:
Dim body As String = "{""query"": ""{products(first: 3, query:\""product_type:Fabric\"") {edges {node {id title} } } }""}"