From bc971331d1a2a9a3902abe81b89498a6a4c62db5 Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Wed, 26 Jul 2023 17:39:21 +0200 Subject: [PATCH] Allocation improvements. (#1009) * Allocation improvements. * Fix usings. --- .../GraphQL/Types/ApplicationMutations.cs | 53 +++++++++++-------- .../GraphQL/Types/ApplicationQueries.cs | 21 ++++---- .../Types/Contents/ComponentGraphType.cs | 14 ++--- .../Types/Contents/ContentGraphType.cs | 28 +++++----- .../Types/Contents/DataFlatGraphType.cs | 14 ++--- .../GraphQL/Types/Contents/DataGraphType.cs | 28 +++++----- .../Types/Contents/DataInputGraphType.cs | 14 ++--- .../GraphQL/Types/Contents/NestedGraphType.cs | 14 ++--- .../Types/Contents/NestedInputGraphType.cs | 7 +-- .../GraphQL/Types/FieldTypeWithSchemaId.cs | 23 ++++++++ .../GraphQL/Types/FieldTypeWithSourceName.cs | 15 ++++++ .../GraphQL/Types/SharedExtensions.cs | 38 ++++++------- .../Api/Config/OpenApi/OpenApiServices.cs | 10 +++- 13 files changed, 175 insertions(+), 104 deletions(-) create mode 100644 backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/FieldTypeWithSchemaId.cs create mode 100644 backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/FieldTypeWithSourceName.cs 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 7b4173ac36..59313878d5 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 @@ -8,6 +8,7 @@ using GraphQL.Types; using Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents; using Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Primitives; +using Squidex.Domain.Apps.Entities.Schemas; namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types; @@ -34,69 +35,79 @@ public ApplicationMutations(Builder builder, IEnumerable schemas) var nonNullContentType = new NonNullGraphType(contentType); - AddField(new FieldType + // Calculate the named if once to avoid allocations. + var schemaid = schemaInfo.Schema.NamedId(); + + AddField(new FieldTypeWithSchemaNamedId { Name = $"create{schemaInfo.TypeName}Content", Arguments = ContentActions.Create.Arguments(inputType), ResolvedType = contentType, Resolver = ContentActions.Create.Resolver, - Description = $"Creates an {schemaInfo.DisplayName} content." - }).WithSchemaNamedId(schemaInfo); + Description = $"Creates an {schemaInfo.DisplayName} content.", + SchemaId = schemaInfo.Schema.NamedId() + }); - AddField(new FieldType + AddField(new FieldTypeWithSchemaNamedId { Name = $"update{schemaInfo.TypeName}Content", Arguments = ContentActions.Update.Arguments(inputType), ResolvedType = contentType, Resolver = ContentActions.Update.Resolver, - Description = $"Update an {schemaInfo.DisplayName} content by id." - }).WithSchemaNamedId(schemaInfo); + Description = $"Update an {schemaInfo.DisplayName} content by id.", + SchemaId = schemaInfo.Schema.NamedId() + }); - AddField(new FieldType + AddField(new FieldTypeWithSchemaNamedId { Name = $"upsert{schemaInfo.TypeName}Content", Arguments = ContentActions.Upsert.Arguments(inputType), ResolvedType = contentType, Resolver = ContentActions.Upsert.Resolver, - Description = $"Upsert an {schemaInfo.DisplayName} content by id." - }).WithSchemaNamedId(schemaInfo); + Description = $"Upsert an {schemaInfo.DisplayName} content by id.", + SchemaId = schemaInfo.Schema.NamedId() + }); - AddField(new FieldType + AddField(new FieldTypeWithSchemaNamedId { Name = $"patch{schemaInfo.TypeName}Content", Arguments = ContentActions.Patch.Arguments(inputType), ResolvedType = contentType, Resolver = ContentActions.Patch.Resolver, - Description = $"Patch an {schemaInfo.DisplayName} content by id." - }).WithSchemaNamedId(schemaInfo); + Description = $"Patch an {schemaInfo.DisplayName} content by id.", + SchemaId = schemaInfo.Schema.NamedId() + }); - AddField(new FieldType + AddField(new FieldTypeWithSchemaNamedId { Name = $"change{schemaInfo.TypeName}Content", Arguments = ContentActions.ChangeStatus.Arguments, ResolvedType = contentType, Resolver = ContentActions.ChangeStatus.Resolver, - Description = $"Change a {schemaInfo.DisplayName} content." - }).WithSchemaNamedId(schemaInfo); + Description = $"Change a {schemaInfo.DisplayName} content.", + SchemaId = schemaInfo.Schema.NamedId() + }); - AddField(new FieldType + AddField(new FieldTypeWithSchemaNamedId { Name = $"delete{schemaInfo.TypeName}Content", Arguments = ContentActions.Delete.Arguments, ResolvedType = EntitySavedGraphType.NonNull, Resolver = ContentActions.Delete.Resolver, - Description = $"Delete an {schemaInfo.DisplayName} content." - }).WithSchemaNamedId(schemaInfo); + Description = $"Delete an {schemaInfo.DisplayName} content.", + SchemaId = schemaInfo.Schema.NamedId() + }); - AddField(new FieldType + AddField(new FieldTypeWithSchemaNamedId { 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); + DeprecationReason = $"Use 'change{schemaInfo.TypeName}Content' instead", + SchemaId = schemaInfo.Schema.NamedId() + }); } Description = "The app mutations."; diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ApplicationQueries.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ApplicationQueries.cs index b59285f1ae..190cb3dacb 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ApplicationQueries.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/ApplicationQueries.cs @@ -37,26 +37,28 @@ public ApplicationQueries(Builder builder, IEnumerable schemaInfos) private void AddContentFind(SchemaInfo schemaInfo, IGraphType contentType) { - AddField(new FieldType + AddField(new FieldTypeWithSchemaId { Name = $"find{schemaInfo.TypeName}Content", Arguments = ContentActions.Find.Arguments, ResolvedType = contentType, Resolver = ContentActions.Find.Resolver, - Description = $"Find an {schemaInfo.DisplayName} content by id." - }).WithSchemaId(schemaInfo); + Description = $"Find an {schemaInfo.DisplayName} content by id.", + SchemaId = schemaInfo.Schema.Id + }); } private void AddContentQueries(Builder builder, SchemaInfo schemaInfo, IGraphType contentType) { - AddField(new FieldType + AddField(new FieldTypeWithSchemaId { Name = $"query{schemaInfo.TypeName}Contents", Arguments = ContentActions.QueryOrReferencing.Arguments, ResolvedType = new ListGraphType(new NonNullGraphType(contentType)), Resolver = ContentActions.QueryOrReferencing.Query, - Description = $"Query {schemaInfo.DisplayName} content items." - }).WithSchemaId(schemaInfo); + Description = $"Query {schemaInfo.DisplayName} content items.", + SchemaId = schemaInfo.Schema.Id + }); var contentResultTyp = builder.GetContentResultType(schemaInfo); @@ -65,14 +67,15 @@ private void AddContentQueries(Builder builder, SchemaInfo schemaInfo, IGraphTyp return; } - AddField(new FieldType + AddField(new FieldTypeWithSchemaId { Name = $"query{schemaInfo.TypeName}ContentsWithTotal", Arguments = ContentActions.QueryOrReferencing.Arguments, ResolvedType = contentResultTyp, Resolver = ContentActions.QueryOrReferencing.QueryWithTotal, - Description = $"Query {schemaInfo.DisplayName} content items with total count." - }).WithSchemaId(schemaInfo); + Description = $"Query {schemaInfo.DisplayName} content items with total count.", + SchemaId = schemaInfo.Schema.Id + }); } private void AddContentQuery(Builder builder) diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/ComponentGraphType.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/ComponentGraphType.cs index 6d51405351..bce5d857da 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/ComponentGraphType.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/ComponentGraphType.cs @@ -33,28 +33,30 @@ public void Initialize(Builder builder, SchemaInfo schemaInfo) { if (fieldInfo.Field.IsComponentLike()) { - AddField(new FieldType + AddField(new FieldTypeWithSourceName { Name = fieldInfo.FieldNameDynamic, Arguments = ContentActions.Json.Arguments, ResolvedType = Scalars.Json, Resolver = FieldVisitor.JsonPath, - Description = fieldInfo.Field.RawProperties.Hints - }).WithSourceName(fieldInfo); + Description = fieldInfo.Field.RawProperties.Hints, + SourceName = fieldInfo.Field.Name + }); } var (resolvedType, resolver, args) = builder.GetGraphType(fieldInfo); if (resolvedType != null && resolver != null) { - AddField(new FieldType + AddField(new FieldTypeWithSourceName { Name = fieldInfo.FieldName, Arguments = args, ResolvedType = resolvedType, Resolver = resolver, - Description = fieldInfo.Field.RawProperties.Hints - }).WithSourceName(fieldInfo); + Description = fieldInfo.Field.RawProperties.Hints, + SourceName = fieldInfo.Field.Name + }); } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/ContentGraphType.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/ContentGraphType.cs index d615e09531..912366bab5 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/ContentGraphType.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/ContentGraphType.cs @@ -95,14 +95,15 @@ private void AddReferencingQueries(Builder builder, SchemaInfo referencingSchema { var contentType = builder.GetContentType(referencingSchemaInfo); - AddField(new FieldType + AddField(new FieldTypeWithSchemaId { Name = $"referencing{referencingSchemaInfo.TypeName}Contents", Arguments = ContentActions.QueryOrReferencing.Arguments, ResolvedType = new ListGraphType(new NonNullGraphType(contentType)), Resolver = ContentActions.QueryOrReferencing.Referencing, - Description = $"Query {referencingSchemaInfo.DisplayName} content items." - }).WithSchemaId(referencingSchemaInfo); + Description = $"Query {referencingSchemaInfo.DisplayName} content items.", + SchemaId = referencingSchemaInfo.Schema.Id + }); var contentResultTyp = builder.GetContentResultType(referencingSchemaInfo); @@ -111,28 +112,30 @@ private void AddReferencingQueries(Builder builder, SchemaInfo referencingSchema return; } - AddField(new FieldType + AddField(new FieldTypeWithSchemaId { Name = $"referencing{referencingSchemaInfo.TypeName}ContentsWithTotal", Arguments = ContentActions.QueryOrReferencing.Arguments, ResolvedType = contentResultTyp, Resolver = ContentActions.QueryOrReferencing.ReferencingWithTotal, - Description = $"Query {referencingSchemaInfo.DisplayName} content items with total count." - }).WithSchemaId(referencingSchemaInfo); + Description = $"Query {referencingSchemaInfo.DisplayName} content items with total count.", + SchemaId = referencingSchemaInfo.Schema.Id + }); } private void AddReferencesQueries(Builder builder, SchemaInfo referencesSchemaInfo) { var contentType = builder.GetContentType(referencesSchemaInfo); - AddField(new FieldType + AddField(new FieldTypeWithSchemaId { Name = $"references{referencesSchemaInfo.TypeName}Contents", Arguments = ContentActions.QueryOrReferencing.Arguments, ResolvedType = new ListGraphType(new NonNullGraphType(contentType)), Resolver = ContentActions.QueryOrReferencing.References, - Description = $"Query {referencesSchemaInfo.DisplayName} content items." - }).WithSchemaId(referencesSchemaInfo); + Description = $"Query {referencesSchemaInfo.DisplayName} content items.", + SchemaId = referencesSchemaInfo.Schema.Id + }); var contentResultTyp = builder.GetContentResultType(referencesSchemaInfo); @@ -141,14 +144,15 @@ private void AddReferencesQueries(Builder builder, SchemaInfo referencesSchemaIn return; } - AddField(new FieldType + AddField(new FieldTypeWithSchemaId { Name = $"references{referencesSchemaInfo.TypeName}ContentsWithTotal", Arguments = ContentActions.QueryOrReferencing.Arguments, ResolvedType = contentResultTyp, Resolver = ContentActions.QueryOrReferencing.ReferencesWithTotal, - Description = $"Query {referencesSchemaInfo.DisplayName} content items with total count." - }).WithSchemaId(referencesSchemaInfo); + Description = $"Query {referencesSchemaInfo.DisplayName} content items with total count.", + SchemaId = referencesSchemaInfo.Schema.Id + }); } private static bool IsReference(SchemaInfo from, SchemaInfo to) diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/DataFlatGraphType.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/DataFlatGraphType.cs index 142ef2be28..dcbac5fd5e 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/DataFlatGraphType.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/DataFlatGraphType.cs @@ -22,28 +22,30 @@ public DataFlatGraphType(Builder builder, SchemaInfo schemaInfo) { if (fieldInfo.Field.IsComponentLike()) { - AddField(new FieldType + AddField(new FieldTypeWithSourceName { Name = fieldInfo.FieldNameDynamic, Arguments = ContentActions.Json.Arguments, ResolvedType = Scalars.Json, Resolver = FieldVisitor.JsonPath, - Description = fieldInfo.Field.RawProperties.Hints - }).WithSourceName(fieldInfo); + Description = fieldInfo.Field.RawProperties.Hints, + SourceName = fieldInfo.Field.Name + }); } var (resolvedType, resolver, args) = builder.GetGraphType(fieldInfo); if (resolver != null) { - AddField(new FieldType + AddField(new FieldTypeWithSourceName { Name = fieldInfo.FieldName, Arguments = args, ResolvedType = resolvedType, Resolver = resolver, - Description = fieldInfo.Field.RawProperties.Hints - }).WithSourceName(fieldInfo); + Description = fieldInfo.Field.RawProperties.Hints, + SourceName = fieldInfo.Field.Name + }); } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/DataGraphType.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/DataGraphType.cs index 0551925c11..1850998887 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/DataGraphType.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/DataGraphType.cs @@ -33,24 +33,26 @@ public DataGraphType(Builder builder, SchemaInfo schemaInfo) foreach (var partitionKey in partitioning.AllKeys) { - fieldGraphType.AddField(new FieldType + fieldGraphType.AddField(new FieldTypeWithSourceName { Name = partitionKey.EscapePartition(), Arguments = ContentActions.Json.Arguments, ResolvedType = Scalars.Json, Resolver = FieldVisitor.JsonPath, - Description = fieldInfo.Field.RawProperties.Hints - }).WithSourceName(partitionKey); + Description = fieldInfo.Field.RawProperties.Hints, + SourceName = partitionKey + }); } fieldGraphType.Description = $"The dynamic structure of the {fieldInfo.DisplayName} field of the {schemaInfo.DisplayName} content type."; - AddField(new FieldType + AddField(new FieldTypeWithSourceName { Name = fieldInfo.FieldNameDynamic, ResolvedType = fieldGraphType, - Resolver = ContentResolvers.Field - }).WithSourceName(fieldInfo); + Resolver = ContentResolvers.Field, + SourceName = fieldInfo.Field.Name + }); } var (resolvedType, resolver, args) = builder.GetGraphType(fieldInfo); @@ -65,24 +67,26 @@ public DataGraphType(Builder builder, SchemaInfo schemaInfo) foreach (var partitionKey in partitioning.AllKeys) { - fieldGraphType.AddField(new FieldType + fieldGraphType.AddField(new FieldTypeWithSourceName { Name = partitionKey.EscapePartition(), Arguments = args, ResolvedType = resolvedType, Resolver = resolver, - Description = fieldInfo.Field.RawProperties.Hints - }).WithSourceName(partitionKey); + Description = fieldInfo.Field.RawProperties.Hints, + SourceName = partitionKey + }); } fieldGraphType.Description = $"The structure of the {fieldInfo.DisplayName} field of the {schemaInfo.DisplayName} content type."; - AddField(new FieldType + AddField(new FieldTypeWithSourceName { Name = fieldInfo.FieldName, ResolvedType = fieldGraphType, - Resolver = ContentResolvers.Field - }).WithSourceName(fieldInfo); + Resolver = ContentResolvers.Field, + SourceName = fieldInfo.Field.Name, + }); } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/DataInputGraphType.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/DataInputGraphType.cs index b9761b5d4a..8c77001a31 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/DataInputGraphType.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/DataInputGraphType.cs @@ -40,23 +40,25 @@ public DataInputGraphType(Builder builder, SchemaInfo schemaInfo) foreach (var partitionKey in partitioning.AllKeys) { - fieldGraphType.AddField(new FieldType + fieldGraphType.AddField(new FieldTypeWithSourceName { Name = partitionKey.EscapePartition(), ResolvedType = resolvedType, Resolver = null, - Description = fieldInfo.Field.RawProperties.Hints - }).WithSourceName(partitionKey); + Description = fieldInfo.Field.RawProperties.Hints, + SourceName = partitionKey + }); } fieldGraphType.Description = $"The structure of the {fieldInfo.DisplayName} field of the {schemaInfo.DisplayName} content input type."; - AddField(new FieldType + AddField(new FieldTypeWithSourceName { Name = fieldInfo.FieldName, ResolvedType = fieldGraphType, - Resolver = null - }).WithSourceName(fieldInfo); + Resolver = null, + SourceName = fieldInfo.Field.Name, + }); } Description = $"The structure of the {schemaInfo.DisplayName} data input type."; diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/NestedGraphType.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/NestedGraphType.cs index 53cf1df32a..caf9ef3730 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/NestedGraphType.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/NestedGraphType.cs @@ -22,28 +22,30 @@ public NestedGraphType(Builder builder, FieldInfo fieldInfo) { if (nestedFieldInfo.Field.IsComponentLike()) { - AddField(new FieldType + AddField(new FieldTypeWithSourceName { Name = nestedFieldInfo.FieldNameDynamic, Arguments = ContentActions.Json.Arguments, ResolvedType = Scalars.Json, Resolver = FieldVisitor.JsonPath, - Description = nestedFieldInfo.Field.RawProperties.Hints - }).WithSourceName(nestedFieldInfo); + Description = nestedFieldInfo.Field.RawProperties.Hints, + SourceName = nestedFieldInfo.Field.Name + }); } var (resolvedType, resolver, args) = builder.GetGraphType(nestedFieldInfo); if (resolvedType != null && resolver != null) { - AddField(new FieldType + AddField(new FieldTypeWithSourceName { Name = nestedFieldInfo.FieldName, Arguments = args, ResolvedType = resolvedType, Resolver = resolver, - Description = nestedFieldInfo.Field.RawProperties.Hints - }).WithSourceName(nestedFieldInfo); + Description = nestedFieldInfo.Field.RawProperties.Hints, + SourceName = nestedFieldInfo.Field.Name + }); } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/NestedInputGraphType.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/NestedInputGraphType.cs index 8408d62bd4..2e3b0b6dbe 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/NestedInputGraphType.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Contents/NestedInputGraphType.cs @@ -27,13 +27,14 @@ public NestedInputGraphType(Builder builder, FieldInfo fieldInfo) continue; } - AddField(new FieldType + AddField(new FieldTypeWithSourceName { Name = nestedFieldInfo.FieldName, ResolvedType = resolvedType, Resolver = null, - Description = nestedFieldInfo.Field.RawProperties.Hints - }).WithSourceName(nestedFieldInfo); + Description = nestedFieldInfo.Field.RawProperties.Hints, + SourceName = nestedFieldInfo.Field.Name, + }); } Description = $"The structure of the {fieldInfo.DisplayName} nested schema."; diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/FieldTypeWithSchemaId.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/FieldTypeWithSchemaId.cs new file mode 100644 index 0000000000..74c05e9665 --- /dev/null +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/FieldTypeWithSchemaId.cs @@ -0,0 +1,23 @@ +// ========================================================================== +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex UG (haftungsbeschraenkt) +// All rights reserved. Licensed under the MIT license. +// ========================================================================== + +using GraphQL.Types; +using Squidex.Infrastructure; + +#pragma warning disable MA0048 // File name must match type name + +namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types; + +internal sealed class FieldTypeWithSchemaId : FieldType +{ + required public DomainId SchemaId { get; set; } +} + +internal sealed class FieldTypeWithSchemaNamedId : FieldType +{ + required public NamedId SchemaId { get; set; } +} diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/FieldTypeWithSourceName.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/FieldTypeWithSourceName.cs new file mode 100644 index 0000000000..4b37a798d8 --- /dev/null +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/FieldTypeWithSourceName.cs @@ -0,0 +1,15 @@ +// ========================================================================== +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex UG (haftungsbeschraenkt) +// All rights reserved. Licensed under the MIT license. +// ========================================================================== + +using GraphQL.Types; + +namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types; + +internal sealed class FieldTypeWithSourceName : FieldType +{ + required public string SourceName { get; set; } +} diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/SharedExtensions.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/SharedExtensions.cs index 8ae27e91b0..5c5ae090b9 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/SharedExtensions.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/SharedExtensions.cs @@ -78,7 +78,6 @@ public static bool IsValidName(this string? name, NamedElement type) try { NameValidator.ValidateDefault(name!, type); - return true; } catch @@ -87,39 +86,34 @@ public static bool IsValidName(this string? name, NamedElement type) } } - internal static FieldType WithSourceName(this FieldType field, string value) - { - return field.WithMetadata(nameof(SourceName), value); - } - - internal static FieldType WithSourceName(this FieldType field, FieldInfo value) - { - return field.WithMetadata(nameof(SourceName), value.Field.Name); - } - internal static string SourceName(this FieldType field) { - return field.GetMetadata(nameof(SourceName))!; - } + if (field is FieldTypeWithSourceName typed) + { + return typed.SourceName; + } - internal static FieldType WithSchemaId(this FieldType field, SchemaInfo value) - { - return field.WithMetadata(nameof(SchemaId), value.Schema.Id); + throw new InvalidOperationException("Invalid field type"); } internal static DomainId SchemaId(this FieldType field) { - return field.GetMetadata(nameof(SchemaId))!; - } + if (field is FieldTypeWithSchemaId typed) + { + return typed.SchemaId; + } - internal static FieldType WithSchemaNamedId(this FieldType field, SchemaInfo value) - { - return field.WithMetadata(nameof(SchemaNamedId), value.Schema.NamedId()); + throw new InvalidOperationException("Invalid field type"); } internal static NamedId SchemaNamedId(this FieldType field) { - return field.GetMetadata>(nameof(SchemaNamedId))!; + if (field is FieldTypeWithSchemaNamedId typed) + { + return typed.SchemaId; + } + + throw new InvalidOperationException("Invalid field type"); } public static IGraphType? InnerType(this IGraphType type) diff --git a/backend/src/Squidex/Areas/Api/Config/OpenApi/OpenApiServices.cs b/backend/src/Squidex/Areas/Api/Config/OpenApi/OpenApiServices.cs index d4ff863670..737fe5e453 100644 --- a/backend/src/Squidex/Areas/Api/Config/OpenApi/OpenApiServices.cs +++ b/backend/src/Squidex/Areas/Api/Config/OpenApi/OpenApiServices.cs @@ -6,6 +6,8 @@ // ========================================================================== using System.Text.Json; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; using NJsonSchema; using NJsonSchema.Generation; using NJsonSchema.Generation.TypeMappers; @@ -64,7 +66,13 @@ public static void AddSquidexOpenApiSettings(this IServiceCollection services) services.AddSingleton(c => { - var settings = new OpenApiDocumentGeneratorSettings(); + var settings = new OpenApiDocumentGeneratorSettings + { + SerializerSettings = new JsonSerializerSettings + { + ContractResolver = new CamelCasePropertyNamesContractResolver() + } + }; ConfigureSchemaSettings(settings, c.GetRequiredService(), true);