Created
January 23, 2021 23:04
-
-
Save JIOO-phoeNIX/6adf5bb5222147c0415ab3845aa73373 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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