tgstation-server 6.16.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
GraphQLGitLabClientFactory.cs
Go to the documentation of this file.
1using System;
2using System.Net.Http.Headers;
3using System.Threading.Tasks;
4
5using Microsoft.Extensions.DependencyInjection;
6
8{
12 public sealed class GraphQLGitLabClientFactory
13 {
19 public static async ValueTask<IGraphQLGitLabClient> CreateClient(string? bearerToken = null)
20 {
21 var serviceCollection = new ServiceCollection();
22
23 var clientBuilder = serviceCollection
24 .AddGraphQLClient();
25 var graphQLEndpoint = new Uri("https://gitlab.com/api/graphql");
26
27 clientBuilder.ConfigureHttpClient(
28 client =>
29 {
30 client.BaseAddress = new Uri("https://gitlab.com/api/graphql");
31 if (bearerToken != null)
32 {
33 client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", bearerToken);
34 }
35 });
36
37 var serviceProvider = serviceCollection.BuildServiceProvider();
38 try
39 {
40 return new GraphQLGitLabClient(serviceProvider);
41 }
42 catch
43 {
44 await serviceProvider.DisposeAsync();
45 throw;
46 }
47 }
48 }
49}
static async ValueTask< IGraphQLGitLabClient > CreateClient(string? bearerToken=null)
Sets up a IGraphQLGitLabClient.