mirror of https://github.com/Squidex/squidex.git
committed by
GitHub
10 changed files with 159 additions and 21 deletions
@ -0,0 +1,46 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using GraphQL.Types; |
|||
using Squidex.Text; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents |
|||
{ |
|||
public sealed class FieldEnumType<T> : EnumerationGraphType |
|||
{ |
|||
public FieldEnumType(string name, string prefix, IEnumerable<T> values) |
|||
{ |
|||
Name = name; |
|||
|
|||
var index = 0; |
|||
|
|||
foreach (var value in values) |
|||
{ |
|||
AddValue(BuildName(value, prefix, index), null, value); |
|||
|
|||
index++; |
|||
} |
|||
} |
|||
|
|||
private static string BuildName(T value, string prefix, int index) |
|||
{ |
|||
var name = value!.ToString()!.Slugify().ToPascalCase(); |
|||
|
|||
if (string.IsNullOrEmpty(name)) |
|||
{ |
|||
name = $"{prefix}_{index}"; |
|||
} |
|||
|
|||
if (!char.IsLetter(name[0])) |
|||
{ |
|||
name = $"{prefix}_{name}"; |
|||
} |
|||
|
|||
return name; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using GraphQL; |
|||
using GraphQL.NewtonsoftJson; |
|||
using Microsoft.AspNetCore.WebUtilities; |
|||
using Newtonsoft.Json; |
|||
|
|||
namespace Squidex.Web.GraphQL |
|||
{ |
|||
public sealed class BufferingDocumentWriter : IDocumentWriter |
|||
{ |
|||
private readonly DocumentWriter documentWriter; |
|||
|
|||
public BufferingDocumentWriter(Action<JsonSerializerSettings> action) |
|||
{ |
|||
documentWriter = new DocumentWriter(action); |
|||
} |
|||
|
|||
public async Task WriteAsync<T>(Stream stream, T value, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
await using (var bufferStream = new FileBufferingWriteStream()) |
|||
{ |
|||
await documentWriter.WriteAsync(bufferStream, value, cancellationToken); |
|||
|
|||
await bufferStream.DrainBufferAsync(stream, cancellationToken); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue