I am unable to retrieve the results of the GraphQL query response returned. The server logs that the request was finished with no error. But the program continues to wait for a response. In the code provided, the Debug.Print statement following the await graphQLHttpClient.SendQueryAsync is never reached. It just indefinitely hangs at this statement and there is not timeout or error.
This code is executed in the ViewModel initializer.
”’
using System.Diagnostics;
using GraphQL;
using GraphQL.Client.Http;
using GraphQL.Client.Serializer.Newtonsoft;
namespace peMove.Maui.LookupViewModels
{
public class RootObject
{
public Documents ErpDocuments { get; set; }
}
public class Documents
{
public getDocument[] Rows { get; set; }
}
public class getDocument
{
public string id1 { get; set; }
public string id2 { get; set; }
public string name { get; set; }
}
public class Document
{
public string Id { get; set; }
public string Name { get; set; }
public string Type { get; set; }
public string TypeShort { get; set; }
public decimal Onhand { get; set; }
public string UofM { get; set; }
public string Note { get; set; }
public Color Color { get; set; }
}
public class Onhand
{
public Location[] Locations { get; set; }
//public Location[] items { get; set; } This will also work on the non-alias
}
public class Location
{
public string location { get; set; }
public string bin { get; set; }
public string lotsn { get; set; }
public float onhand { get; set; }
}
public class ViewModel_L
{
public static Document erpDoc;
static readonly string Url = "https://1eaa-98-103-130-98.ngrok-free.app"; // ngrok public url
private static GraphQLHttpClient graphQLHttpClient;
private static string qlQuery = @"{
products(filter:{and: [{fac: {eq: ""Default""}}, {fpartno: {eq: ""WF201W""}}, {frev: {eq: ""000""}} ]})
{
parts : items {
id1 : fpartno
id2 : frev
name : fdescript
}
}
}";
public static async Task RunAsync()
{
var graphQLOptions = new GraphQLHttpClientOptions
{
EndPoint = new Uri($"{Url}/graphql", UriKind.Absolute)
};
var graphQLHttpClient = new GraphQLHttpClient(graphQLOptions, new NewtonsoftJsonSerializer());
var productRequest = new GraphQLRequest { Query = qlQuery };
getDocument[] docs = null;
try
{
var graphQLResponse = await graphQLHttpClient.SendQueryAsync<RootObject>(productRequest);
Debug.Print("");
docs = graphQLResponse.Data.ErpDocuments.Rows;
}
catch (Exception ex)
{
Debug.Print(ex.Message);
}
if (docs !=null)
{
foreach (var doc in docs)
{
erpDoc.Id = doc.id1 + ":" + doc.id2;
erpDoc.Name = doc.name;
erpDoc.Type = "Part";
erpDoc.TypeShort = erpDoc.Type[..1]; // First charater
erpDoc.Onhand = 0;
//erpDoc.Note = "UofM: " + doc.uofm + " Source: " + doc.source + " Purchased: " + doc.purchased + " Status: " + doc.status;
erpDoc.Color = MauiProgram.colorPart;
}
}
else
{
Console.WriteLine("No matching Parts found in query.");
}
}
public ViewModel_L()
{
RunAsync().GetAwaiter().GetResult();
this.ErpDocument = erpDoc;
}
public Document ErpDocument { get; set; }
}
}
”’
1
you are creating a deadlock by calling an async method in the constructor.
1 hour ago