Skip to content

Commit

Permalink
Small QOL tweaks to Version.Create and ProjectModelsFilter (#210)
Browse files Browse the repository at this point in the history
* Version Create now returns a Version

* ProjectModelsFilter now has optional args
  • Loading branch information
JR-Morgan authored Jan 24, 2025
1 parent ee10e9d commit f0c7169
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 32 deletions.
18 changes: 6 additions & 12 deletions src/Speckle.Sdk/Api/GraphQL/Inputs/ProjectInputs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,12 @@ public sealed record ProjectInviteCreateInput(string? email, string? role, strin
public sealed record ProjectInviteUseInput(bool accept, string projectId, string token);

public sealed record ProjectModelsFilter(
IReadOnlyList<string>? contributors,
IReadOnlyList<string>? excludeIds,
IReadOnlyList<string>? ids,
bool? onlyWithVersions,
string? search,
IReadOnlyList<string>? sourceApps
);

public sealed record ProjectModelsTreeFilter(
IReadOnlyList<string>? contributors,
string? search,
IReadOnlyList<string>? sourceApps
IReadOnlyList<string>? contributors = null,
IReadOnlyList<string>? excludeIds = null,
IReadOnlyList<string>? ids = null,
bool? onlyWithVersions = null,
string? search = null,
IReadOnlyList<string>? sourceApps = null
);

public sealed record ProjectUpdateInput(
Expand Down
22 changes: 18 additions & 4 deletions src/Speckle.Sdk/Api/GraphQL/Resources/VersionResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,28 @@ query VersionGetVersions($projectId: String!, $modelId: String!, $limit: Int!, $
/// <param name="cancellationToken"></param>
/// <returns>id of the created <see cref="Version"/></returns>
/// <inheritdoc cref="ISpeckleGraphQLClient.ExecuteGraphQLRequest{T}"/>
public async Task<string> Create(CreateVersionInput input, CancellationToken cancellationToken = default)
public async Task<Version> Create(CreateVersionInput input, CancellationToken cancellationToken = default)
{
//language=graphql
const string QUERY = """
mutation Create($input: CreateVersionInput!) {
data:versionMutations {
data:create(input: $input) {
data:id
id
referencedObject
message
sourceApplication
createdAt
previewUrl
authorUser {
id
name
bio
company
verified
role
avatar
}
}
}
}
Expand All @@ -143,9 +157,9 @@ mutation Create($input: CreateVersionInput!) {
GraphQLRequest request = new() { Query = QUERY, Variables = new { input } };

var response = await _client
.ExecuteGraphQLRequest<RequiredResponse<RequiredResponse<RequiredResponse<string>>>>(request, cancellationToken)
.ExecuteGraphQLRequest<RequiredResponse<RequiredResponse<Version>>>(request, cancellationToken)
.ConfigureAwait(false);
return response.data.data.data;
return response.data.data;
}

/// <param name="input"></param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Speckle.Sdk.Api.GraphQL.Resources;
using Speckle.Sdk.Common;
using Xunit;
using Version = Speckle.Sdk.Api.GraphQL.Models.Version;

namespace Speckle.Sdk.Tests.Integration.API.GraphQL.Resources;

Expand All @@ -14,17 +15,17 @@ public class CommentResourceTests
private readonly CommentResource Sut;
private readonly Project _project;
private readonly Model _model;
private readonly string _versionId;
private readonly Version _version;
private readonly Comment _comment;

// Constructor for setup
public CommentResourceTests()
{
// Synchronous operations converted to async Task.Run for constructor
_testUser = Task.Run(async () => await Fixtures.SeedUserWithClient()).Result!;
_project = Task.Run(async () => await _testUser.Project.Create(new("Test project", "", null))).Result!;
_model = Task.Run(async () => await _testUser.Model.Create(new("Test Model 1", "", _project.id))).Result!;
_versionId = Task.Run(async () => await Fixtures.CreateVersion(_testUser, _project.id, _model.id)).Result!;
_testUser = Task.Run(async () => await Fixtures.SeedUserWithClient()).Result;
_project = Task.Run(async () => await _testUser.Project.Create(new("Test project", "", null))).Result;
_model = Task.Run(async () => await _testUser.Model.Create(new("Test Model 1", "", _project.id))).Result;
_version = Task.Run(async () => await Fixtures.CreateVersion(_testUser, _project.id, _model.id)).Result;
_comment = Task.Run(CreateComment).Result!;
Sut = _testUser.Comment;
}
Expand Down Expand Up @@ -110,6 +111,6 @@ public async Task Reply()

private async Task<Comment> CreateComment()
{
return await Fixtures.CreateComment(_testUser, _project.id, _model.id, _versionId);
return await Fixtures.CreateComment(_testUser, _project.id, _model.id, _version.id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Speckle.Sdk.Api.GraphQL.Models;
using Speckle.Sdk.Api.GraphQL.Resources;
using Xunit;
using Version = Speckle.Sdk.Api.GraphQL.Models.Version;

namespace Speckle.Sdk.Tests.Integration.API.GraphQL.Resources;

Expand All @@ -14,7 +15,7 @@ public class SubscriptionResourceTests : IAsyncLifetime
private Client _testUser;
private Project _testProject;
private Model _testModel;
private string _testVersion;
private Version _testVersion;

private SubscriptionResource Sut => _testUser.Subscription;

Expand Down Expand Up @@ -109,7 +110,7 @@ public async Task ProjectVersionsUpdated_SubscriptionIsCalled()
await Task.Delay(WAIT_PERIOD); // Give time for subscription to be triggered

subscriptionMessage.Should().NotBeNull();
subscriptionMessage!.id.Should().Be(created);
subscriptionMessage!.id.Should().Be(created.id);
subscriptionMessage.type.Should().Be(ProjectVersionsUpdatedMessageType.CREATED);
subscriptionMessage.version.Should().NotBeNull();
}
Expand All @@ -125,7 +126,7 @@ public async Task ProjectCommentsUpdated_SubscriptionIsCalled()

await Task.Delay(WAIT_PERIOD); // Give time to subscription to be setup

var created = await Fixtures.CreateComment(_testUser, _testProject.id, _testModel.id, _testVersion);
var created = await Fixtures.CreateComment(_testUser, _testProject.id, _testModel.id, _testVersion.id);

await Task.Delay(WAIT_PERIOD); // Give time for subscription to be triggered

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public async Task InitializeAsync()
_model1 = await _testUser.Model.Create(new("Test Model 1", "", _project.id));
_model2 = await _testUser.Model.Create(new("Test Model 2", "", _project.id));

string versionId = await Fixtures.CreateVersion(_testUser, _project.id, _model1.id);

_version = await Sut.Get(versionId, _project.id);
_version = await Fixtures.CreateVersion(_testUser, _project.id, _model1.id);
}

[Fact]
Expand Down
3 changes: 2 additions & 1 deletion tests/Speckle.Sdk.Tests.Integration/Fixtures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Speckle.Sdk.Models;
using Speckle.Sdk.Tests.Unit.Serialisation;
using Speckle.Sdk.Transports;
using Version = Speckle.Sdk.Api.GraphQL.Models.Version;

namespace Speckle.Sdk.Tests.Integration;

Expand All @@ -39,7 +40,7 @@ public static async Task<Client> SeedUserWithClient()
return ServiceProvider.GetRequiredService<IClientFactory>().Create(await SeedUser());
}

public static async Task<string> CreateVersion(Client client, string projectId, string modelId)
public static async Task<Version> CreateVersion(Client client, string projectId, string modelId)
{
using var remote = ServiceProvider.GetRequiredService<IServerTransportFactory>().Create(client.Account, projectId);
var (objectId, _) = await ServiceProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Speckle.Sdk.Models;
using Speckle.Sdk.Serialisation;
using Speckle.Sdk.Transports;
using Version = Speckle.Sdk.Api.GraphQL.Models.Version;

namespace Speckle.Sdk.Tests.Performance.Benchmarks;

Expand Down Expand Up @@ -62,21 +63,21 @@ await dataSource
}

[Benchmark(Baseline = true)]
public async Task<string> Send_old()
public async Task<Version> Send_old()
{
using SQLiteTransport local = new();
var res = await _operations.Send(_testData, [_remote, local]);
return await TagVersion($"Send_old {Guid.NewGuid()}", res.rootObjId);
}

[Benchmark]
public async Task<string> Send_new()
public async Task<Version> Send_new()
{
var res = await _operations.Send2(new(acc.serverInfo.url), _project.id, acc.token, _testData, null, default);
return await TagVersion($"Send_new {Guid.NewGuid()}", res.RootId);
}

private async Task<string> TagVersion(string name, string objectId)
private async Task<Version> TagVersion(string name, string objectId)
{
var model = await client.Model.Create(new(name, null, _project.id));
return await client.Version.Create(new(objectId, model.id, _project.id));
Expand Down

0 comments on commit f0c7169

Please sign in to comment.