Skip to content

Commit

Permalink
Added explicit nullability to GqlModels (#144)
Browse files Browse the repository at this point in the history
* Added explicit nullability to GqlModels

* data and alignment

* ModelsWithVersions

* Models

* active user

* Invites and active user fixes

* Invite changes

* Subscriptions

* Fixed subscription tests

* corrected nullability of projectinput

* removed unused mutation responses

* format

---------

Co-authored-by: Alan Rynne <[email protected]>
  • Loading branch information
JR-Morgan and AlanRynne authored Nov 4, 2024
1 parent 91c4090 commit fba0c46
Show file tree
Hide file tree
Showing 36 changed files with 486 additions and 421 deletions.
2 changes: 2 additions & 0 deletions Speckle.Sdk.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=QL/@EntryIndexedValue">QL</s:String></wpf:ResourceDictionary>
14 changes: 13 additions & 1 deletion src/Speckle.Sdk/Api/GraphQL/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using GraphQL.Client.Http;
using Microsoft.Extensions.Logging;
using Speckle.Newtonsoft.Json;
using Speckle.Newtonsoft.Json.Serialization;
using Speckle.Sdk.Api.GraphQL;
using Speckle.Sdk.Api.GraphQL.Resources;
using Speckle.Sdk.Api.GraphQL.Serializer;
Expand Down Expand Up @@ -272,7 +273,18 @@ private static GraphQLHttpClient CreateGraphQLClient(Account account, HttpClient
: null;
},
},
new NewtonsoftJsonSerializer(),
new NewtonsoftJsonSerializer(
new JsonSerializerSettings()
{
ContractResolver = new CamelCasePropertyNamesContractResolver { IgnoreIsSpecifiedMembers = true }, //(Default)
MissingMemberHandling = MissingMemberHandling.Error, //(not default) If you query for a member that doesn't exist, this will throw (except websocket responses see https://github.com/graphql-dotnet/graphql-client/issues/660)
Converters =
{
new ConstantCaseEnumConverter(),
} //(Default) enums will be serialized using the GraphQL const case standard
,
}
),
httpClient
);

Expand Down
2 changes: 2 additions & 0 deletions src/Speckle.Sdk/Api/GraphQL/ISpeckleGraphQLClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using GraphQL;
using Speckle.Newtonsoft.Json;

namespace Speckle.Sdk.Api.GraphQL;

Expand All @@ -8,6 +9,7 @@ internal interface ISpeckleGraphQLClient
/// <exception cref="SpeckleGraphQLException">All other request errors</exception>
/// <exception cref="OperationCanceledException">The <paramref name="cancellationToken"/> requested a cancel</exception>
/// <exception cref="ObjectDisposedException">This <see cref="Client"/> already been disposed</exception>
/// <exception cref="JsonSerializationException">The response failed to deserialize, probably because the server version is incompatible with this version of the SDK, or there is a mistake in a query (queried for a property that isn't in the C# model, or a required property was null)</exception>
internal Task<T> ExecuteGraphQLRequest<T>(GraphQLRequest request, CancellationToken cancellationToken);

/// <exception cref="SpeckleGraphQLForbiddenException">"FORBIDDEN" on "UNAUTHORIZED" response from server</exception>
Expand Down
2 changes: 1 addition & 1 deletion src/Speckle.Sdk/Api/GraphQL/Inputs/ProjectInputs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public sealed record ProjectModelsFilter(
IReadOnlyList<string>? ids,
bool? onlyWithVersions,
string? search,
IReadOnlyList<string> sourceApps
IReadOnlyList<string>? sourceApps
);

public sealed record ProjectModelsTreeFilter(
Expand Down
8 changes: 8 additions & 0 deletions src/Speckle.Sdk/Api/GraphQL/Inputs/UserInputs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Speckle.Sdk.Api.GraphQL.Inputs;

public sealed record UserUpdateInput(
string? avatar = null,
string? bio = null,
string? company = null,
string? name = null
);
30 changes: 0 additions & 30 deletions src/Speckle.Sdk/Api/GraphQL/Models/Activity.cs

This file was deleted.

26 changes: 24 additions & 2 deletions src/Speckle.Sdk/Api/GraphQL/Models/Collections.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
namespace Speckle.Sdk.Api.GraphQL.Models;
using Speckle.Newtonsoft.Json;

namespace Speckle.Sdk.Api.GraphQL.Models;

public class ResourceCollection<T>
{
[property: JsonProperty(Required = Required.Always)]
public int totalCount { get; init; }

[property: JsonProperty(Required = Required.Always)]
public List<T> items { get; init; }

[property: JsonProperty(Required = Required.AllowNull)]
public string? cursor { get; init; }
}

public sealed class CommentReplyAuthorCollection : ResourceCollection<LimitedUser> { }
public sealed class CommentReplyAuthorCollection
{
[property: JsonProperty(Required = Required.Always)]
public int totalCount { get; init; }

[property: JsonProperty(Required = Required.Always)]
public List<LimitedUser> items { get; init; }
}

public sealed class UserSearchResultCollection
{
[property: JsonProperty(Required = Required.Always)]
public List<LimitedUser> items { get; init; }

[property: JsonProperty(Required = Required.AllowNull)]
public string? cursor { get; init; }
}

public sealed class ProjectCommentCollection : ResourceCollection<Comment>
{
[property: JsonProperty(Required = Required.Always)]
public int totalArchivedCount { get; init; }
}
8 changes: 3 additions & 5 deletions src/Speckle.Sdk/Api/GraphQL/Models/Comment.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#nullable disable

namespace Speckle.Sdk.Api.GraphQL.Models;
namespace Speckle.Sdk.Api.GraphQL.Models;

public sealed class Comment
{
Expand All @@ -10,12 +8,12 @@ public sealed class Comment
public DateTime createdAt { get; init; }
public bool hasParent { get; init; }
public string id { get; init; }
public Comment parent { get; init; }
public Comment? parent { get; init; }
public string rawText { get; init; }
public ResourceCollection<Comment> replies { get; init; }
public CommentReplyAuthorCollection replyAuthors { get; init; }
public List<ResourceIdentifier> resources { get; init; }
public string screenshot { get; init; }
public string? screenshot { get; init; }
public DateTime updatedAt { get; init; }
public DateTime? viewedAt { get; init; }
public List<ViewerResourceItem> viewerResources { get; init; }
Expand Down
9 changes: 4 additions & 5 deletions src/Speckle.Sdk/Api/GraphQL/Models/FileUpload.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#nullable disable

using Speckle.Sdk.Api.GraphQL.Enums;
using Speckle.Sdk.Api.GraphQL.Enums;

namespace Speckle.Sdk.Api.GraphQL.Models;

public sealed class FileUpload
{
public string convertedCommitId { get; init; }
public string? convertedCommitId { get; init; }
public DateTime convertedLastUpdate { get; init; }
public string? convertedMessage { get; init; }
public FileUploadConversionStatus convertedStatus { get; init; }
public string convertedVersionId { get; init; }
public string fileName { get; init; }
public int fileSize { get; init; }
public string fileType { get; init; }
public string id { get; init; }
public Model model { get; init; }
public Model? model { get; init; }
public string modelName { get; init; }
public string projectId { get; init; }
public bool uploadComplete { get; init; }
Expand Down
17 changes: 8 additions & 9 deletions src/Speckle.Sdk/Api/GraphQL/Models/Model.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
#nullable disable
namespace Speckle.Sdk.Api.GraphQL.Models;
namespace Speckle.Sdk.Api.GraphQL.Models;

public sealed class Model
public class Model
{
public LimitedUser author { get; init; }
public List<ModelsTreeItem> childrenTree { get; init; }
public ResourceCollection<Comment> commentThreads { get; init; }
public DateTime createdAt { get; init; }
public string description { get; init; }
public string? description { get; init; }
public string displayName { get; init; }
public string id { get; init; }
public string name { get; init; }
public List<FileUpload> pendingImportedVersions { get; init; }
public Uri previewUrl { get; init; }
public Uri? previewUrl { get; init; }
public DateTime updatedAt { get; init; }
}

public sealed class ModelWithVersions : Model
{
public ResourceCollection<Version> versions { get; init; }
public Version version { get; init; }
}
6 changes: 2 additions & 4 deletions src/Speckle.Sdk/Api/GraphQL/Models/ModelsTreeItem.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#nullable disable

namespace Speckle.Sdk.Api.GraphQL.Models;
namespace Speckle.Sdk.Api.GraphQL.Models;

public sealed class ModelsTreeItem
{
public List<ModelsTreeItem> children { get; init; }
public string fullName { get; init; }
public bool hasChildren { get; init; }
public string id { get; init; }
public Model model { get; init; }
public Model? model { get; init; }
public string name { get; init; }
public DateTime updatedAt { get; init; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#nullable disable

namespace Speckle.Sdk.Api.GraphQL.Models;
namespace Speckle.Sdk.Api.GraphQL.Models;

public sealed class PendingStreamCollaborator
{
Expand All @@ -13,6 +11,6 @@ public sealed class PendingStreamCollaborator
public string title { get; init; }
public string role { get; init; }
public LimitedUser invitedBy { get; init; }
public LimitedUser user { get; init; }
public string token { get; init; }
public LimitedUser? user { get; init; }
public string? token { get; init; }
}
32 changes: 15 additions & 17 deletions src/Speckle.Sdk/Api/GraphQL/Models/Project.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
#nullable disable
using Speckle.Sdk.Api.GraphQL.Enums;
using Speckle.Sdk.Api.GraphQL.Enums;

namespace Speckle.Sdk.Api.GraphQL.Models;

public sealed class Project
public class Project
{
public bool AllowPublicComments { get; init; }
public ProjectCommentCollection commentThreads { get; init; }
public bool allowPublicComments { get; init; }
public DateTime createdAt { get; init; }
public string description { get; init; }
public string? description { get; init; }
public string id { get; init; }
public List<PendingStreamCollaborator> invitedTeam { get; init; }
public ResourceCollection<Model> models { get; init; }
public string name { get; init; }
public List<FileUpload> pendingImportedModels { get; init; }
public string role { get; init; }
public string? role { get; init; }
public List<string> sourceApps { get; init; }
public List<ProjectCollaborator> team { get; init; }
public DateTime updatedAt { get; init; }
public ProjectVisibility visibility { get; init; }
public string? workspaceId { get; init; }
}

public List<ViewerResourceGroup> viewerResources { get; init; }
public ResourceCollection<Version> versions { get; init; }
public Model model { get; init; }
public List<ModelsTreeItem> modelChildrenTree { get; init; }
public ResourceCollection<ModelsTreeItem> modelsTree { get; init; }
public sealed class ProjectWithModels : Project
{
public ResourceCollection<Model> models { get; init; }
}

public string workspaceId { get; init; }
public sealed class ProjectWithTeam : Project
{
public List<PendingStreamCollaborator> invitedTeam { get; init; }
public List<ProjectCollaborator> team { get; init; }
}
5 changes: 2 additions & 3 deletions src/Speckle.Sdk/Api/GraphQL/Models/ProjectCollaborator.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#nullable disable

namespace Speckle.Sdk.Api.GraphQL.Models;
namespace Speckle.Sdk.Api.GraphQL.Models;

public sealed class ProjectCollaborator
{
public string id { get; init; }
public string role { get; init; }
public LimitedUser user { get; init; }
}
3 changes: 1 addition & 2 deletions src/Speckle.Sdk/Api/GraphQL/Models/ResourceIdentifier.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable disable
using Speckle.Sdk.Api.GraphQL.Enums;
using Speckle.Sdk.Api.GraphQL.Enums;

namespace Speckle.Sdk.Api.GraphQL.Models;

Expand Down
44 changes: 0 additions & 44 deletions src/Speckle.Sdk/Api/GraphQL/Models/Responses/MutationResponses.cs

This file was deleted.

Loading

0 comments on commit fba0c46

Please sign in to comment.