graphql-client
graphql-client copied to clipboard
Problem: SendQueryAsync no response
Problem
As the title suggestest i send a graphql request, i do this in 3 different situations but in one of those the method SendQueryAsync just stops without any errors(tried try catch and breakpoints).
####Details I have one Class to do this request, i use it mutliple times, but in one case it doesn't work and i have no idea why, or how to debbug it.
There is nothing noticable in the Stacktrace aswell as far as im concerned
###This is my Code
using GermanFishing.Model.GraphQLImages;
using GraphQL.Client.Http;
using GraphQL.Client.Serializer.Newtonsoft;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace GermanFishing.ViewModel
{
public class UserViewModel
{
public User user_profile { get; set; }
public UserViewModel()
{
user_profile = new User();
}
//Consume User Data from Graphql
public async Task GetProfileData()
{
var client = new GraphQLHttpClient(new GraphQLHttpClientOptions
{
EndPoint = new Uri("https://www.german-fishing.de/graphql"),
}, new NewtonsoftJsonSerializer());
client.HttpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + Convert.ToString(Application.Current.Properties["Login"]));
var request = new GraphQLHttpRequest
{
Query = @"
query {
me {
name
unreadNotifications {
data
}
abonnements {
id
place {
id
name
}
}
}
}"
};
var response = await client.SendQueryAsync<UserImage>(request).ConfigureAwait(false);
this.user_profile = response.Data.me;
}
}
}
Any suggestions how to approach this ?
Can you turn on / check logs on the server side?
Can you turn on / check logs on the server side?
This is where it gets wacky, server gets a post request returns a 200 code, nothing weird or irregular happening there
###Additional Information it could be that im in an Async Deadlock here is the Code where i acctually call it
using GermanFishing.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace GermanFishing.ViewModel.Authentication
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class Authentification
{
public Authentification()
{
}
public bool Auth()
{
if (IsLoggedIn() && KeyActive())
{
return true;
}
else
{
return false;
}
}
private bool IsLoggedIn()
{
bool is_logged_in = Application.Current.Properties.ContainsKey("IsLoggedIn") ? Convert.ToBoolean(Application.Current.Properties["IsLoggedIn"]) : false;
return is_logged_in;
}
private bool KeyActive()
{
UserViewModel user_view_model = new UserViewModel();
Task task = user_view_model.GetProfileData();
task.Wait();
if (user_view_model.user_profile == null)
{
return false;
}
return true;
}
}
}
Same thing here, after calling SendQueryAsync synchronously with ".Result" on Task nothing happens, no logs no errors.
I can PR fix of this.
@masouri assumes one of your GetProfileData calls (which is deadlocked) is from contextual thread (GUI or HttpContext), and you call it like GetProfileData().Result. If so, you're in same problem with @ognjensuvakov. I got same problem by calling SendQueryAsync<...>(...).Result from GUI thread (WinForms).
As a temporary workaround, you can try to wrap SendQueryAsync into Task.Run call like this:
var response = Task.Run(async () => await client.SendQueryAsync<UserImage>(request)).Result;
It will call SendQueryAsync on thread pool and will not capture the synchronization context, so you can avoid deadlock.