-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathWorkspaceResource.cs
More file actions
116 lines (106 loc) · 3.06 KB
/
WorkspaceResource.cs
File metadata and controls
116 lines (106 loc) · 3.06 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
107
108
109
110
111
112
113
114
115
116
using GraphQL;
using Speckle.Sdk.Api.GraphQL.Inputs;
using Speckle.Sdk.Api.GraphQL.Models;
using Speckle.Sdk.Api.GraphQL.Models.Responses;
namespace Speckle.Sdk.Api.GraphQL.Resources;
public sealed class WorkspaceResource
{
private readonly ISpeckleGraphQLClient _client;
internal WorkspaceResource(ISpeckleGraphQLClient client)
{
_client = client;
}
/// <param name="workspaceId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <inheritdoc cref="ISpeckleGraphQLClient.ExecuteGraphQLRequest{T}"/>
public async Task<Workspace> Get(string workspaceId, CancellationToken cancellationToken = default)
{
//language=graphql
const string QUERY = """
query WorkspaceGet($workspaceId: String!) {
data:workspace(id: $workspaceId) {
id
name
role
slug
logoUrl
createdAt
updatedAt
readOnly
description
permissions {
canCreateProject {
authorized
code
message
}
}
}
}
""";
var request = new GraphQLRequest { Query = QUERY, Variables = new { workspaceId } };
var response = await _client
.ExecuteGraphQLRequest<RequiredResponse<Workspace>>(request, cancellationToken)
.ConfigureAwait(false);
return response.data;
}
/// <param name="workspaceId"></param>
/// <param name="limit">Max number of projects to fetch</param>
/// <param name="cursor">Optional cursor for pagination</param>
/// <param name="filter"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <inheritdoc cref="ISpeckleGraphQLClient.ExecuteGraphQLRequest{T}"/>
/// <see cref="Get"/>
public async Task<ResourceCollection<Project>> GetProjects(
string workspaceId,
int limit = ServerLimits.DEFAULT_PAGINATION_REQUEST,
string? cursor = null,
WorkspaceProjectsFilter? filter = null,
CancellationToken cancellationToken = default
)
{
//language=graphql
const string QUERY = """
query Workspace($workspaceId: String!, $limit: Int!, $cursor: String, $filter: WorkspaceProjectsFilter) {
data:workspace(id: $workspaceId) {
data:projects(limit: $limit, cursor: $cursor, filter: $filter) {
cursor
items {
allowPublicComments
createdAt
description
id
name
role
sourceApps
updatedAt
visibility
workspaceId
}
totalCount
}
}
}
""";
var request = new GraphQLRequest
{
Query = QUERY,
Variables = new
{
workspaceId,
limit,
cursor,
filter,
},
};
var response = await _client
.ExecuteGraphQLRequest<RequiredResponse<RequiredResponse<ResourceCollection<Project>>>>(
request,
cancellationToken
)
.ConfigureAwait(false);
return response.data.data;
}
}