GraphQL (SendQueryAsync) 从 Maui ViewModel 初始值设定项执行时死锁

GraphQL (SendQueryAsync) deadlocked when executing from Maui ViewModel initializer

提问人:BumpaRoy 提问时间:11/4/2023 更新时间:11/4/2023 访问量:18

问:

当我在 C# 控制台应用程序中运行 GraphQL 查询时,它运行良好。使用完全相同的 GraphQL 客户端,当我尝试从 Maui 的 ViewModel 初始值设定项运行它时,它挂起的代码和属性。引发异常:“System.Reflection.TargetInvocationException:调用目标引发了异常。

如果我手动构建列表,它可以工作,但我想从查询构建列表。

'''

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;
        }

    }       
}

'''

C# GraphQL Maui

评论

0赞 Jason 11/4/2023
什么是 ?InnerException

答: 暂无答案