Repository navigation
Expand file tree
/
Copy pathGraphQLClientFactory.cs
More file actions
52 lines (48 loc) · 1.85 KB
/
Copy pathGraphQLClientFactory.cs
File metadata and controls
52 lines (48 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.ComponentModel.Composition;
using System.IO;
using System.Runtime.Caching;
using System.Threading.Tasks;
using GitHub.Info;
using GitHub.Models;
using GitHub.Primitives;
using Octokit.GraphQL;
namespace GitHub.Api
{
/// <summary>
/// Creates GraphQL <see cref="Octokit.GraphQL.IConnection"/>s for querying the
/// GitHub GraphQL API.
/// </summary>
[Export(typeof(IGraphQLClientFactory))]
[PartCreationPolicy(CreationPolicy.Shared)]
public class GraphQLClientFactory : IGraphQLClientFactory
{
readonly IKeychain keychain;
readonly IProgram program;
readonly FileCache cache;
/// <summary>
/// Initializes a new instance of the <see cref="GraphQLClientFactory"/> class.
/// </summary>
/// <param name="keychain">The <see cref="IKeychain"/> to use.</param>
/// <param name="program">The program details.</param>
[ImportingConstructor]
public GraphQLClientFactory(IKeychain keychain, IProgram program)
{
this.keychain = keychain;
this.program = program;
var cachePath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
ApplicationInfo.ApplicationName,
"GraphQLCache");
cache = new FileCache(cachePath);
}
/// <inheirtdoc/>
public Task<IGraphQLClient> CreateConnection(HostAddress address)
{
var credentials = new GraphQLKeychainCredentialStore(keychain, address);
var header = new ProductHeaderValue(program.ProductHeader.Name, program.ProductHeader.Version);
var connection = new Connection(header, address.GraphQLUri, credentials);
return Task.FromResult<IGraphQLClient>(new GraphQLClient(connection, cache));
}
}
}