-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathOtherUserResource.cs
More file actions
106 lines (95 loc) · 2.68 KB
/
OtherUserResource.cs
File metadata and controls
106 lines (95 loc) · 2.68 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using GraphQL;
using Speckle.Sdk.Api.GraphQL.Models;
using Speckle.Sdk.Api.GraphQL.Models.Responses;
namespace Speckle.Sdk.Api.GraphQL.Resources;
public sealed class OtherUserResource
{
private readonly ISpeckleGraphQLClient _client;
internal OtherUserResource(ISpeckleGraphQLClient client)
{
_client = client;
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="cancellationToken"></param>
/// <returns>the requested user, or null if the user does not exist</returns>
/// <inheritdoc cref="ISpeckleGraphQLClient.ExecuteGraphQLRequest{T}"/>
public async Task<LimitedUser?> Get(string id, CancellationToken cancellationToken = default)
{
//language=graphql
const string QUERY = """
query LimitedUser($id: String!) {
data:otherUser(id: $id) {
id
name
bio
company
avatar
verified
role
}
}
""";
var request = new GraphQLRequest { Query = QUERY, Variables = new { id } };
var response = await _client
.ExecuteGraphQLRequest<NullableResponse<LimitedUser?>>(request, cancellationToken)
.ConfigureAwait(false);
return response.data;
}
/// <summary>
/// Searches for a user on the server, by name or email
/// </summary>
/// <param name="query">String to search for. Must be at least 3 characters</param>
/// <param name="limit">Max number of users to fetch</param>
/// <param name="cursor">Optional cursor for pagination</param>
/// <param name="emailOnly"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <inheritdoc cref="ISpeckleGraphQLClient.ExecuteGraphQLRequest{T}"/>
public async Task<UserSearchResultCollection> UserSearch(
string query,
int limit = ServerLimits.DEFAULT_PAGINATION_REQUEST,
string? cursor = null,
bool emailOnly = false,
CancellationToken cancellationToken = default
)
{
//language=graphql
const string QUERY = """
query Users($input: UsersRetrievalInput!) {
data:users(input: $input) {
cursor
items {
id
name
bio
company
avatar
verified
role
}
}
}
""";
var request = new GraphQLRequest
{
Query = QUERY,
Variables = new
{
input = new
{
query,
limit,
emailOnly,
cursor,
},
},
};
var response = await _client
.ExecuteGraphQLRequest<RequiredResponse<UserSearchResultCollection>>(request, cancellationToken)
.ConfigureAwait(false);
return response.data;
}
}