GraphQL (SendQueryAsync) deadlocked when executing from Maui ViewModel initializer

GraphQL (SendQueryAsync) deadlocked when executing from Maui ViewModel initializer


0

GraphQL query runs just fine when I run it in a C# console app. Using the exact same GraphQL Client, similar code and properties it hangs when I try to run it from a ViewModel initializer in Maui. An exception is thrown: "System.Reflection.TargetInvocationException: ‘Exception has been thrown by the target of an invocation.’"

If I manually build the list it works, but I want to build the list from a query.

”’

using System;
using System.Diagnostics;
using GraphQL;
using GraphQL.Client.Http;
using GraphQL.Client.Serializer.Newtonsoft;
using Microsoft.Maui.Graphics;

namespace peMove.Maui.LookupViewModels
{
    public class RootObject
    {
        //products - cursor
        public Documents cursor { get; set; }
    }

    public class Documents
    {
        //parts - Rows
        public getDocument[] Rows { get; set; }
        //public Part[] items { get; set; }  This will also work on the non-alias
    }

    public class getDocument
    {
        //items - Row
        public string id1 { get; set; }
        public string id2 { get; set; }
        public string name { get; set; }
        public string uofm {  get; set; }
        public string source { get; set; }
        public string purchased { get; set; }
        public string status { get; set; }
    }

    public class ViewModel_L
    {

        public getDocument[] RtnCursor { get; set; }
        public static getDocument[] rtnRows;
        private static GraphQLHttpClient graphQLHttpClient;
        private static string qlQuery = @"{ 
                            products(filter:{and: [{fac: {eq: ""Default""}}, {fpartno: {contains: ""WF""}}, {frev: {eq: ""000""}} ]})
                            {
                                parts : items {
                                    id1 : fpartno
                                    id2 : frev
                                    name : fdescript
                                    uofm : fmeasure
                                    source : fsource
                                    purchased : fcpurchase
                                    status : fcstscode
                                }
                            }
            }";

        public ViewModel_L()
        {
            RunAsync().GetAwaiter().GetResult();
            this.RtnCursor = rtnRows;
        }
        
        private static async Task RunAsync()

        {
            var graphQLOptions = new GraphQLHttpClientOptions
            {
                EndPoint = new Uri("https://localhost:5001/graphql", UriKind.Absolute)
            };

            var graphQLHttpClient = new GraphQLHttpClient(graphQLOptions, new NewtonsoftJsonSerializer());

            var productRequest = new GraphQLRequest { Query = qlQuery };

            var graphQLResponse = await graphQLHttpClient.SendQueryAsync<RootObject>(productRequest).ConfigureAwait(false);
            Debug.Print("");

            //parts
            rtnRows= graphQLResponse.Data.cursor.Rows;
        }

    }       
}

”’

1

  • what is the InnerException?

    – Jason

    1 hour ago


Load 4 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *