mirror of https://github.com/Squidex/squidex.git
committed by
GitHub
23 changed files with 243 additions and 116 deletions
@ -1,60 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Squidex.Infrastructure; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents |
|||
{ |
|||
internal sealed class Names |
|||
{ |
|||
// Reserver names that are used for other GraphQL types.
|
|||
private static readonly HashSet<string> ReservedNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase) |
|||
{ |
|||
"Asset", |
|||
"AssetResultDto", |
|||
"Content", |
|||
"Component", |
|||
"EntityCreatedResultDto", |
|||
"EntitySavedResultDto", |
|||
"JsonScalar", |
|||
"JsonPrimitive", |
|||
"User" |
|||
}; |
|||
private readonly Dictionary<string, int> takenNames = new Dictionary<string, int>(); |
|||
|
|||
public string this[string name, bool isEntity = true] |
|||
{ |
|||
get => GetName(name, isEntity); |
|||
} |
|||
|
|||
private string GetName(string name, bool isEntity) |
|||
{ |
|||
Guard.NotNullOrEmpty(name); |
|||
|
|||
if (!char.IsLetter(name[0])) |
|||
{ |
|||
name = "gql_" + name; |
|||
} |
|||
else if (isEntity && ReservedNames.Contains(name)) |
|||
{ |
|||
name = $"{name}Entity"; |
|||
} |
|||
|
|||
// Avoid duplicate names.
|
|||
if (!takenNames.TryGetValue(name, out var offset)) |
|||
{ |
|||
takenNames[name] = 0; |
|||
return name; |
|||
} |
|||
|
|||
takenNames[name] = ++offset; |
|||
|
|||
// Add + 1 to all offsets for backwards-compatibility.
|
|||
return $"{name}{offset + 1}"; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue