From 3fa17837aedf4f7828186421d50a8d5d686c6076 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 16 Jan 2023 11:47:31 +0100 Subject: [PATCH] Fix null checks. --- .../GraphQL/Types/ApplicationMutations.cs | 40 ++++++++++++++++--- .../Contents/GraphQL/GraphQLMutationTests.cs | 25 +++++++++--- 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ApplicationMutations.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ApplicationMutations.cs index dc9b67cec..7b4173ac3 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ApplicationMutations.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ApplicationMutations.cs @@ -7,6 +7,7 @@ using GraphQL.Types; using Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents; +using Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Primitives; namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types; @@ -26,8 +27,7 @@ internal sealed class ApplicationMutations : ObjectGraphType var contentType = builder.GetContentType(schemaInfo); - // We cannot check before if all fields can be resolved. This might not be the case, e.g. if a reference is empty. - if (contentType == null || contentType.Fields.Count == 0) + if (contentType == null) { continue; } @@ -38,7 +38,7 @@ internal sealed class ApplicationMutations : ObjectGraphType { Name = $"create{schemaInfo.TypeName}Content", Arguments = ContentActions.Create.Arguments(inputType), - ResolvedType = nonNullContentType, + ResolvedType = contentType, Resolver = ContentActions.Create.Resolver, Description = $"Creates an {schemaInfo.DisplayName} content." }).WithSchemaNamedId(schemaInfo); @@ -47,7 +47,7 @@ internal sealed class ApplicationMutations : ObjectGraphType { Name = $"update{schemaInfo.TypeName}Content", Arguments = ContentActions.Update.Arguments(inputType), - ResolvedType = nonNullContentType, + ResolvedType = contentType, Resolver = ContentActions.Update.Resolver, Description = $"Update an {schemaInfo.DisplayName} content by id." }).WithSchemaNamedId(schemaInfo); @@ -56,7 +56,7 @@ internal sealed class ApplicationMutations : ObjectGraphType { Name = $"upsert{schemaInfo.TypeName}Content", Arguments = ContentActions.Upsert.Arguments(inputType), - ResolvedType = nonNullContentType, + ResolvedType = contentType, Resolver = ContentActions.Upsert.Resolver, Description = $"Upsert an {schemaInfo.DisplayName} content by id." }).WithSchemaNamedId(schemaInfo); @@ -65,10 +65,38 @@ internal sealed class ApplicationMutations : ObjectGraphType { Name = $"patch{schemaInfo.TypeName}Content", Arguments = ContentActions.Patch.Arguments(inputType), - ResolvedType = nonNullContentType, + ResolvedType = contentType, Resolver = ContentActions.Patch.Resolver, Description = $"Patch an {schemaInfo.DisplayName} content by id." }).WithSchemaNamedId(schemaInfo); + + AddField(new FieldType + { + Name = $"change{schemaInfo.TypeName}Content", + Arguments = ContentActions.ChangeStatus.Arguments, + ResolvedType = contentType, + Resolver = ContentActions.ChangeStatus.Resolver, + Description = $"Change a {schemaInfo.DisplayName} content." + }).WithSchemaNamedId(schemaInfo); + + AddField(new FieldType + { + Name = $"delete{schemaInfo.TypeName}Content", + Arguments = ContentActions.Delete.Arguments, + ResolvedType = EntitySavedGraphType.NonNull, + Resolver = ContentActions.Delete.Resolver, + Description = $"Delete an {schemaInfo.DisplayName} content." + }).WithSchemaNamedId(schemaInfo); + + AddField(new FieldType + { + Name = $"publish{schemaInfo.TypeName}Content", + Arguments = ContentActions.ChangeStatus.Arguments, + ResolvedType = contentType, + Resolver = ContentActions.ChangeStatus.Resolver, + Description = $"Publish a {schemaInfo.DisplayName} content.", + DeprecationReason = $"Use 'change{schemaInfo.TypeName}Content' instead" + }).WithSchemaNamedId(schemaInfo); } Description = "The app mutations."; diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLMutationTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLMutationTests.cs index 01e2226de..829f0e2e3 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLMutationTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLMutationTests.cs @@ -64,7 +64,10 @@ public class GraphQLMutationTests : GraphQLTestBase } } }, - data = (object?)null + data = new + { + createMySchemaContent = (object?)null + } }; AssertResult(expected, actual); @@ -215,7 +218,10 @@ public class GraphQLMutationTests : GraphQLTestBase } } }, - data = (object?)null + data = new + { + updateMySchemaContent = (object?)null + } }; AssertResult(expected, actual); @@ -329,7 +335,10 @@ public class GraphQLMutationTests : GraphQLTestBase } } }, - data = (object?)null + data = new + { + upsertMySchemaContent = (object?)null + } }; AssertResult(expected, actual); @@ -445,7 +454,10 @@ public class GraphQLMutationTests : GraphQLTestBase } } }, - data = (object?)null + data = new + { + patchMySchemaContent = (object?)null + } }; AssertResult(expected, actual); @@ -559,7 +571,10 @@ public class GraphQLMutationTests : GraphQLTestBase } } }, - data = (object?)null + data = new + { + changeMySchemaContent = (object?)null + } }; AssertResult(expected, actual);