From 32aec8e4ffb1d8e3ba48e950acf1a43f06d7acac Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Thu, 16 Jan 2020 23:22:16 -0800 Subject: [PATCH] Added GQL client + helper methods. --- BodyshopUploader/BodyshopUploader.csproj | 1 + BodyshopUploader/Utils/Auth.cs | 4 +- BodyshopUploader/Utils/GraphQL.cs | 19 +++++++++ .../ViewModels/MainViewModel.commands.cs | 2 +- BodyshopUploader/ViewModels/MainViewModel.cs | 41 ++++++++++++++++++- 5 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 BodyshopUploader/Utils/GraphQL.cs diff --git a/BodyshopUploader/BodyshopUploader.csproj b/BodyshopUploader/BodyshopUploader.csproj index 356321b..680f953 100644 --- a/BodyshopUploader/BodyshopUploader.csproj +++ b/BodyshopUploader/BodyshopUploader.csproj @@ -247,6 +247,7 @@ + diff --git a/BodyshopUploader/Utils/Auth.cs b/BodyshopUploader/Utils/Auth.cs index 8e6dbda..80f1ff8 100644 --- a/BodyshopUploader/Utils/Auth.cs +++ b/BodyshopUploader/Utils/Auth.cs @@ -25,8 +25,8 @@ namespace BodyshopUploader.Utils logger.Trace("Firebase Auth Token {0}.", authlink.FirebaseToken); logger.Trace("Firebase Refresh Token {0}.", authlink.RefreshToken); logger.Trace("Firebase Auth Token expires in {0} seconds.", authlink.ExpiresIn); - //tokenTimer.Interval = (authlink.ExpiresIn - 600) * 1000; //Set the token to refresh 10 minutes before it has to. - tokenTimer.Interval = 10000; //Set the token to refresh 10 minutes before it has to. + tokenTimer.Interval = (authlink.ExpiresIn - 600) * 1000; //Set the token to refresh 10 minutes before it has to. + //tokenTimer.Interval = 10000; //Set the token to refresh 10 minutes before it has to. logger.Trace("Refresh timer interval set to {0}ms", (authlink.ExpiresIn - 600) * 1000); tokenTimer.Elapsed += TokenTimer_Tick; tokenTimer.Start(); diff --git a/BodyshopUploader/Utils/GraphQL.cs b/BodyshopUploader/Utils/GraphQL.cs new file mode 100644 index 0000000..a677a8c --- /dev/null +++ b/BodyshopUploader/Utils/GraphQL.cs @@ -0,0 +1,19 @@ +using GraphQL.Client; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BodyshopUploader.Utils +{ + public static class GraphQL + { + 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; + } + } +} diff --git a/BodyshopUploader/ViewModels/MainViewModel.commands.cs b/BodyshopUploader/ViewModels/MainViewModel.commands.cs index 85eaf73..202b7e3 100644 --- a/BodyshopUploader/ViewModels/MainViewModel.commands.cs +++ b/BodyshopUploader/ViewModels/MainViewModel.commands.cs @@ -16,7 +16,7 @@ namespace BodyshopUploader.ViewModels p => true, async p => { - await Utils.Auth.Refresh(); + await TestGql(); }); } return _testCommand; diff --git a/BodyshopUploader/ViewModels/MainViewModel.cs b/BodyshopUploader/ViewModels/MainViewModel.cs index c7f2623..4fe8c80 100644 --- a/BodyshopUploader/ViewModels/MainViewModel.cs +++ b/BodyshopUploader/ViewModels/MainViewModel.cs @@ -1,4 +1,6 @@ -using System; +using GraphQL.Client; +using GraphQL.Common.Request; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +8,7 @@ using System.Threading.Tasks; namespace BodyshopUploader.ViewModels { - public partial class MainViewModel:BaseViewModel + public partial class MainViewModel : BaseViewModel { private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); @@ -14,5 +16,40 @@ namespace BodyshopUploader.ViewModels { logger.Trace("Main VM Created."); } + + public async Task TestGql() + { + var r = new GraphQLRequest + { + Query = @" + query { + jobs { + id + est_number + ro_number + job_status { + id + name + } + scheduled_completion + scheduled_delivery + vehicle { + id + v_model_yr + v_make_desc + v_model_desc + plate_no + } + } + } + " + }; + + using (var g = Utils.GraphQL.CreateGQLClient()) + { + var graphQLResponse = await g.PostAsync(r); + logger.Info(graphQLResponse.Data.jobs); + } + } } }