Added GQL client + helper methods.

This commit is contained in:
Patrick Fic
2020-01-16 23:22:16 -08:00
parent d77e0d1c02
commit 32aec8e4ff
5 changed files with 62 additions and 5 deletions

View File

@@ -247,6 +247,7 @@
<Compile Include="Utils\Auth.cs" />
<Compile Include="Utils\BaseModel.cs" />
<Compile Include="Utils\BaseViewModel.cs" />
<Compile Include="Utils\GraphQL.cs" />
<Compile Include="Utils\LoginHelpers.cs" />
<Compile Include="Utils\RelayCommand.cs" />
<Compile Include="Utils\UiConverters.cs" />

View File

@@ -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();

View File

@@ -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;
}
}
}

View File

@@ -16,7 +16,7 @@ namespace BodyshopUploader.ViewModels
p => true,
async p =>
{
await Utils.Auth.Refresh();
await TestGql();
});
}
return _testCommand;

View File

@@ -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;
@@ -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);
}
}
}
}