mirror of https://github.com/Squidex/squidex.git
committed by
GitHub
12 changed files with 278 additions and 136 deletions
@ -0,0 +1,16 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using Squidex.Infrastructure.Json.Objects; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Core.Contents |
||||
|
{ |
||||
|
public sealed class FlatContentData : Dictionary<string, IJsonValue?> |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,57 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using GraphQL.Resolvers; |
||||
|
using GraphQL.Types; |
||||
|
using Squidex.Domain.Apps.Core.Contents; |
||||
|
using Squidex.Domain.Apps.Entities.Schemas; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types |
||||
|
{ |
||||
|
public sealed class ContentDataFlatGraphType : ObjectGraphType<FlatContentData> |
||||
|
{ |
||||
|
public ContentDataFlatGraphType(ISchemaEntity schema, string schemaName, string schemaType, IGraphModel model) |
||||
|
{ |
||||
|
Name = $"{schemaType}DataFlatDto"; |
||||
|
|
||||
|
foreach (var (field, fieldName, typeName) in schema.SchemaDef.Fields.SafeFields()) |
||||
|
{ |
||||
|
var (resolvedType, valueResolver) = model.GetGraphType(schema, field, fieldName); |
||||
|
|
||||
|
if (valueResolver != null) |
||||
|
{ |
||||
|
AddField(new FieldType |
||||
|
{ |
||||
|
Name = fieldName, |
||||
|
Resolver = PartitionResolver(valueResolver, field.Name), |
||||
|
ResolvedType = resolvedType, |
||||
|
Description = field.RawProperties.Hints |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
Description = $"The structure of the flat {schemaName} data type."; |
||||
|
} |
||||
|
|
||||
|
private static FuncFieldResolver<object?> PartitionResolver(ValueResolver valueResolver, string key) |
||||
|
{ |
||||
|
return new FuncFieldResolver<object?>(c => |
||||
|
{ |
||||
|
var source = (FlatContentData)c.Source; |
||||
|
|
||||
|
if (source.TryGetValue(key, out var value) && value != null) |
||||
|
{ |
||||
|
return valueResolver(value, c); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue