Refactor GQL code. Auto load and save active shops. Auto start monitors.

This commit is contained in:
Patrick Fic
2020-01-20 15:42:59 -08:00
parent bc5cb13113
commit fa75c58633
11 changed files with 166 additions and 68 deletions

View File

@@ -1,4 +1,6 @@
using GraphQL.Client;
using GraphQL.Common.Request;
using GraphQL.Common.Response;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -9,11 +11,33 @@ namespace BodyshopUploader.Utils
{
public static class GraphQL
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
public static GraphQLClient CreateGQLClient()
{
var graphQLClient = new GraphQLClient("https://bodyshop-dev-db.herokuapp.com/v1/graphql");
graphQLClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + Utils.Auth.authlink.FirebaseToken);
return graphQLClient;
}
public static async Task<dynamic> ExecuteQuery(GraphQLRequest r)
{
using (var g = Utils.GraphQL.CreateGQLClient())
{
logger.Trace("Firing GQL Query: {0} {1}", r.Query.ToString(), r.Variables);
var graphQLResponse = await g.PostAsync(r);
if (graphQLResponse.Errors == null)
{
logger.Trace("GQL Response: {0}", graphQLResponse.Data);
return graphQLResponse.Data;
}
else
{
logger.Error("Error executing query.");
Array.ForEach(graphQLResponse.Errors, x => logger.Error(x.ToString()));
return null;
}
}
}
}
}