Compare commits

...

4 Commits

Author SHA1 Message Date
Jedd Morgan c517dead03 Internal 2026-03-24 10:24:43 +00:00
Jedd Morgan 2b61ab7d2e fallback mechanism 2026-03-24 10:04:44 +00:00
Jedd Morgan 4b319499c3 Fix mistake 2026-03-23 16:10:44 +00:00
Jedd Morgan d4055c6ff1 Avoid deprecated fields 2026-03-23 16:03:20 +00:00
6 changed files with 75 additions and 32 deletions
@@ -1,3 +1,5 @@
using Speckle.Newtonsoft.Json;
namespace Speckle.Sdk.Api.GraphQL.Models; namespace Speckle.Sdk.Api.GraphQL.Models;
public class LimitedWorkspace public class LimitedWorkspace
@@ -6,8 +8,12 @@ public class LimitedWorkspace
public string name { get; init; } public string name { get; init; }
public string? role { get; init; } public string? role { get; init; }
public string slug { get; init; } public string slug { get; init; }
public string? logo { get; init; } public string? logoUri { get; init; }
public string? description { get; init; } public string? description { get; init; }
[JsonIgnore]
[Obsolete($"Deprecated, use {nameof(logoUri)} instead", true)]
public string? logo { get; init; }
} }
public class Workspace : LimitedWorkspace public class Workspace : LimitedWorkspace
@@ -16,9 +22,13 @@ public class Workspace : LimitedWorkspace
public DateTime updatedAt { get; init; } public DateTime updatedAt { get; init; }
public bool readOnly { get; init; } public bool readOnly { get; init; }
public WorkspacePermissionChecks permissions { get; init; } public WorkspacePermissionChecks permissions { get; init; }
[JsonIgnore]
[Obsolete("Workspaces no longer have creation state, is always created true", true)]
public WorkspaceCreationState? creationState { get; init; } public WorkspaceCreationState? creationState { get; init; }
} }
[Obsolete("Workspaces no longer have creation state, is always created true")]
public sealed class WorkspaceCreationState public sealed class WorkspaceCreationState
{ {
public bool completed { get; init; } public bool completed { get; init; }
@@ -264,15 +264,11 @@ public sealed class ActiveUserResource
name name
role role
slug slug
logo logoUrl
createdAt createdAt
updatedAt updatedAt
readOnly readOnly
description description
creationState
{
completed
}
permissions { permissions {
canCreateProject { canCreateProject {
authorized authorized
@@ -317,7 +313,7 @@ public sealed class ActiveUserResource
/// <remarks>note this returns a <see cref="LimitedWorkspace"/>, because it may be a workspace the user is not a member of</remarks> /// <remarks>note this returns a <see cref="LimitedWorkspace"/>, because it may be a workspace the user is not a member of</remarks>
/// <inheritdoc cref="ISpeckleGraphQLClient.ExecuteGraphQLRequest{T}"/> /// <inheritdoc cref="ISpeckleGraphQLClient.ExecuteGraphQLRequest{T}"/>
/// <exception cref="SpeckleException">The ActiveUser could not be found (e.g. the client is not authenticated)</exception> /// <exception cref="SpeckleException">The ActiveUser could not be found (e.g. the client is not authenticated)</exception>
public async Task<LimitedWorkspace?> GetActiveWorkspace(CancellationToken cancellationToken = default) private async Task<LimitedWorkspace?> GetActiveWorkspace_Legacy(CancellationToken cancellationToken = default)
{ {
//language=graphql //language=graphql
const string QUERY = """ const string QUERY = """
@@ -328,7 +324,6 @@ public sealed class ActiveUserResource
name name
role role
slug slug
logo
description description
} }
} }
@@ -349,6 +344,47 @@ public sealed class ActiveUserResource
return response.data.data; return response.data.data;
} }
public async Task<LimitedWorkspace?> GetActiveWorkspace(CancellationToken cancellationToken = default)
{
//language=graphql
const string QUERY = """
query ActiveUser {
data:activeUser {
data:activeWorkspace {
id
name
role
slug
logoUrl
description
}
}
}
""";
var request = new GraphQLRequest { Query = QUERY };
NullableResponse<NullableResponse<LimitedWorkspace?>?> response;
try
{
response = await _client
.ExecuteGraphQLRequest<NullableResponse<NullableResponse<LimitedWorkspace?>?>>(request, cancellationToken)
.ConfigureAwait(false);
}
catch (SpeckleGraphQLInvalidQueryException)
{
//v2.x.x servers do not have a logoUrl property
return await GetActiveWorkspace_Legacy(cancellationToken).ConfigureAwait(false);
}
if (response.data is null)
{
throw new SpeckleException("GraphQL response indicated that the ActiveUser could not be found");
}
return response.data.data;
}
/// <param name="limit">Max number of projects to fetch</param> /// <param name="limit">Max number of projects to fetch</param>
/// <param name="cursor">Optional cursor for pagination</param> /// <param name="cursor">Optional cursor for pagination</param>
/// <param name="filter">Optional filter</param> /// <param name="filter">Optional filter</param>
@@ -52,7 +52,6 @@ public sealed class OtherUserResource
/// <param name="query">String to search for. Must be at least 3 characters</param> /// <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="limit">Max number of users to fetch</param>
/// <param name="cursor">Optional cursor for pagination</param> /// <param name="cursor">Optional cursor for pagination</param>
/// <param name="archived"></param>
/// <param name="emailOnly"></param> /// <param name="emailOnly"></param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns></returns> /// <returns></returns>
@@ -61,26 +60,25 @@ public sealed class OtherUserResource
string query, string query,
int limit = ServerLimits.DEFAULT_PAGINATION_REQUEST, int limit = ServerLimits.DEFAULT_PAGINATION_REQUEST,
string? cursor = null, string? cursor = null,
bool archived = false,
bool emailOnly = false, bool emailOnly = false,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
) )
{ {
//language=graphql //language=graphql
const string QUERY = """ const string QUERY = """
query UserSearch($query: String!, $limit: Int!, $cursor: String, $archived: Boolean, $emailOnly: Boolean) { query Users($input: UsersRetrievalInput!) {
data:userSearch(query: $query, limit: $limit, cursor: $cursor, archived: $archived, emailOnly: $emailOnly) { data:users(input: $input) {
cursor cursor
items { items {
id id
name name
bio bio
company company
avatar avatar
verified verified
role role
} }
} }
} }
"""; """;
@@ -89,11 +87,13 @@ public sealed class OtherUserResource
Query = QUERY, Query = QUERY,
Variables = new Variables = new
{ {
query, input = new
limit, {
cursor, query,
archived, limit,
emailOnly, emailOnly,
cursor,
},
}, },
}; };
@@ -76,6 +76,7 @@ public sealed class SubscriptionResource : IDisposable
/// <summary>Subscribe to updates to resource comments/threads. Optionally specify resource ID string to only receive updates regarding comments for those resources</summary> /// <summary>Subscribe to updates to resource comments/threads. Optionally specify resource ID string to only receive updates regarding comments for those resources</summary>
/// <remarks><inheritdoc cref="CreateUserProjectsUpdatedSubscription"/></remarks> /// <remarks><inheritdoc cref="CreateUserProjectsUpdatedSubscription"/></remarks>
/// <inheritdoc cref="ISpeckleGraphQLClient.SubscribeTo{T}"/> /// <inheritdoc cref="ISpeckleGraphQLClient.SubscribeTo{T}"/>
[Obsolete("Comments are now issues, and we've not update SDKs with the new subs")]
public Subscription<ProjectCommentsUpdatedMessage> CreateProjectCommentsUpdatedSubscription( public Subscription<ProjectCommentsUpdatedMessage> CreateProjectCommentsUpdatedSubscription(
ViewerUpdateTrackingTarget target ViewerUpdateTrackingTarget target
) )
@@ -28,15 +28,11 @@ public sealed class WorkspaceResource
name name
role role
slug slug
logo logoUrl
createdAt createdAt
updatedAt updatedAt
readOnly readOnly
description description
creationState
{
completed
}
permissions { permissions {
canCreateProject { canCreateProject {
authorized authorized
@@ -21,7 +21,7 @@ public class WorkspaceResourceTests
return testUser; return testUser;
} }
[Fact] [Fact, Trait("Server", "Internal")]
public async Task TestGetWorkspace() public async Task TestGetWorkspace()
{ {
var ex = await Assert.ThrowsAsync<AggregateException>(async () => _ = await Sut.Get("non-existent-id")); var ex = await Assert.ThrowsAsync<AggregateException>(async () => _ = await Sut.Get("non-existent-id"));