From 41a8248db295d7cb5787837d67d00fa99ffebf3b Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 22 Mar 2020 18:33:20 +0100 Subject: [PATCH] Partially fixed. --- .../Contents/GraphQL/Types/Extensions.cs | 19 +++++++++++++------ .../Contents/GraphQL/GraphQLQueriesTests.cs | 16 +++++++++++++++- .../Contents/GraphQL/GraphQLTestBase.cs | 10 ++++++++++ 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Extensions.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Extensions.cs index 6d0e5b1e3..f752a6a77 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Extensions.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/GraphQL/Types/Extensions.cs @@ -19,19 +19,26 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types public static IEnumerable<(T Field, string Name, string Type)> SafeFields(this IEnumerable fields) where T : IField { var allFields = - fields.ForApi() - .Select(f => (Field: f, Name: f.Name.ToCamelCase(), Type: f.TypeName())).GroupBy(x => x.Name) - .Select(g => - { - return g.Select((f, i) => (f.Field, f.Name.SafeString(i), f.Type.SafeString(i))); - }) + fields.FieldNames() + .GroupBy(x => x.Name) + .Select(g => g.Select((f, i) => (f.Field, f.Name.SafeString(i), f.Type.SafeString(i)))) .SelectMany(x => x); return allFields; } + private static IEnumerable<(T Field, string Name, string Type)> FieldNames(this IEnumerable fields) where T : IField + { + return fields.ForApi().Select(field => (field, field.Name.ToCamelCase(), field.TypeName())); + } + private static string SafeString(this string value, int index) { + if (value.Length > 0 && !char.IsLetter(value[0])) + { + value = "gql_" + value; + } + if (index > 0) { return value + (index + 1); diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLQueriesTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLQueriesTests.cs index c9cd4b9ee..3e0966faf 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLQueriesTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLQueriesTests.cs @@ -784,7 +784,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL } [Fact] - public async Task Should_return_single_content_with_duplicate_names() + public async Task Should_return_single_content_with_fixed_names() { var contentId = Guid.NewGuid(); var content = CreateContent(contentId, Guid.Empty, Guid.Empty); @@ -793,6 +793,12 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL query { findMySchemaContent(id: """") { data { + gql_2Numbers { + iv + } + gql_2Numbers2 { + iv + } myNumber { iv } @@ -822,6 +828,14 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL { data = new { + gql_2Numbers = new + { + iv = 22 + }, + gql_2Numbers2 = new + { + iv = 23 + }, myNumber = new { iv = 1 diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLTestBase.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLTestBase.cs index d7d2f0816..1eb9bcf4b 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLTestBase.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLTestBase.cs @@ -88,6 +88,10 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL .AddBoolean(121, "nested-boolean") .AddNumber(122, "nested-number") .AddNumber(123, "nested_number")) + .AddNumber(14, "2_numbers", Partitioning.Invariant, + new NumberFieldProperties()) + .AddNumber(15, "2-numbers", Partitioning.Invariant, + new NumberFieldProperties()) .SetScripts(new SchemaScripts { Query = "" }); schema = Mocks.Schema(appId, schemaId, schemaDef); @@ -123,6 +127,12 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL .AddField("my-assets", new ContentFieldData() .AddValue("iv", JsonValue.Array(assetId.ToString()))) + .AddField("2_numbers", + new ContentFieldData() + .AddValue("iv", 22)) + .AddField("2-numbers", + new ContentFieldData() + .AddValue("iv", 23)) .AddField("my-number", new ContentFieldData() .AddValue("iv", 1.0))