Skip to content

Instantly share code, notes, and snippets.

@JIOO-phoeNIX
Created January 23, 2021 23:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JIOO-phoeNIX/6adf5bb5222147c0415ab3845aa73373 to your computer and use it in GitHub Desktop.
Save JIOO-phoeNIX/6adf5bb5222147c0415ab3845aa73373 to your computer and use it in GitHub Desktop.
using GraphQL;
using GraphQL.Client.Http;
using GraphQL.Client.Serializer.Newtonsoft;
using ModernHttpClient;
using Newtonsoft.Json;
using System;
using System.Threading.Tasks;
namespace GraphQLSampleAppUI.DataAccess
{
public class Mutation
{
private static GraphQLHttpClient graphQLHttpClient;
static Mutation()
{
var uri = new Uri("https://localhost:44351/graphql");
var graphQLOptions = new GraphQLHttpClientOptions
{
EndPoint = uri,
HttpMessageHandler = new NativeMessageHandler(),
};
graphQLHttpClient = new GraphQLHttpClient(graphQLOptions, new NewtonsoftJsonSerializer());
}
public static async Task<T> ExceuteMutationAsyn<T>(string graphQLQueryType, string completeQueryString)
{
try
{
var request = new GraphQLRequest
{
Query = completeQueryString
};
var response = await graphQLHttpClient.SendMutationAsync<object>(request);
var stringResult = response.Data.ToString();
stringResult = stringResult.Replace($"\"{graphQLQueryType}\":", string.Empty);
stringResult = stringResult.Remove(0, 1);
stringResult = stringResult.Remove(stringResult.Length - 1, 1);
var result = JsonConvert.DeserializeObject<T>(stringResult);
return result;
}
catch (Exception ex)
{
throw;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment