mirror of https://github.com/Squidex/squidex.git
committed by
GitHub
47 changed files with 379 additions and 564 deletions
@ -1,79 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Collections.Generic; |
|||
using GraphQL.Types; |
|||
using Squidex.Domain.Apps.Core.Contents; |
|||
using Squidex.Infrastructure.Json.Objects; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Primitives |
|||
{ |
|||
internal static class Converters |
|||
{ |
|||
public static ContentData ToContentData(this IDictionary<string, object> source, IComplexGraphType type) |
|||
{ |
|||
var result = new ContentData(); |
|||
|
|||
foreach (var field in type.Fields) |
|||
{ |
|||
if (source.TryGetValue(field.Name, out var t) && t is IDictionary<string, object> nested && field.ResolvedType is IComplexGraphType complexType) |
|||
{ |
|||
result[field.SourceName()] = nested.ToFieldData(complexType); |
|||
} |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
|
|||
public static ContentFieldData ToFieldData(this IDictionary<string, object> source, IComplexGraphType type) |
|||
{ |
|||
var result = new ContentFieldData(); |
|||
|
|||
foreach (var field in type.Fields) |
|||
{ |
|||
if (source.TryGetValue(field.Name, out var value)) |
|||
{ |
|||
if (value is List<object> list && field.ResolvedType.Flatten() is IComplexGraphType nestedType) |
|||
{ |
|||
var arr = new JsonArray(); |
|||
|
|||
foreach (var item in list) |
|||
{ |
|||
if (item is IDictionary<string, object> nested) |
|||
{ |
|||
arr.Add(nested.ToNestedData(nestedType)); |
|||
} |
|||
} |
|||
|
|||
result[field.SourceName()] = arr; |
|||
} |
|||
else |
|||
{ |
|||
result[field.SourceName()] = JsonConverter.ParseJson(value); |
|||
} |
|||
} |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
|
|||
public static IJsonValue ToNestedData(this IDictionary<string, object> source, IComplexGraphType type) |
|||
{ |
|||
var result = JsonValue.Object(); |
|||
|
|||
foreach (var field in type.Fields) |
|||
{ |
|||
if (source.TryGetValue(field.Name, out var value)) |
|||
{ |
|||
result[field.SourceName()] = JsonConverter.ParseJson(value); |
|||
} |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
} |
|||
} |
|||
@ -1,32 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using GraphQL.Language.AST; |
|||
using GraphQL.Types; |
|||
using NodaTime; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Primitives |
|||
{ |
|||
internal sealed class InstantConverter : IAstFromValueConverter |
|||
{ |
|||
public static readonly InstantConverter Instance = new InstantConverter(); |
|||
|
|||
private InstantConverter() |
|||
{ |
|||
} |
|||
|
|||
public IValue Convert(object value, IGraphType type) |
|||
{ |
|||
return new InstantValueNode((Instant)value); |
|||
} |
|||
|
|||
public bool Matches(object value, IGraphType type) |
|||
{ |
|||
return type is InstantGraphType; |
|||
} |
|||
} |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using GraphQL.Language.AST; |
|||
using NodaTime; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Primitives |
|||
{ |
|||
internal sealed class InstantValueNode : ValueNode<Instant> |
|||
{ |
|||
public InstantValueNode(Instant value) |
|||
{ |
|||
Value = value; |
|||
} |
|||
|
|||
protected override bool Equals(ValueNode<Instant> node) |
|||
{ |
|||
return Equals(Value, node.Value); |
|||
} |
|||
} |
|||
} |
|||
@ -1,72 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Collections.Generic; |
|||
using GraphQL.Language.AST; |
|||
using GraphQL.Types; |
|||
using Squidex.Infrastructure.Json.Objects; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Primitives |
|||
{ |
|||
internal sealed class JsonConverter : IAstFromValueConverter |
|||
{ |
|||
public static readonly JsonConverter Instance = new JsonConverter(); |
|||
|
|||
private JsonConverter() |
|||
{ |
|||
} |
|||
|
|||
public IValue Convert(object value, IGraphType type) |
|||
{ |
|||
return new JsonValueNode(ParseJson(value)); |
|||
} |
|||
|
|||
public bool Matches(object value, IGraphType type) |
|||
{ |
|||
return type is JsonGraphType; |
|||
} |
|||
|
|||
public static IJsonValue ParseJson(object value) |
|||
{ |
|||
switch (value) |
|||
{ |
|||
case ListValue listValue: |
|||
return ParseJson(listValue.Value); |
|||
|
|||
case ObjectValue objectValue: |
|||
return ParseJson(objectValue.Value); |
|||
|
|||
case Dictionary<string, object> dictionary: |
|||
{ |
|||
var json = JsonValue.Object(); |
|||
|
|||
foreach (var (key, inner) in dictionary) |
|||
{ |
|||
json[key] = ParseJson(inner); |
|||
} |
|||
|
|||
return json; |
|||
} |
|||
|
|||
case List<object> list: |
|||
{ |
|||
var array = JsonValue.Array(); |
|||
|
|||
foreach (var item in list) |
|||
{ |
|||
array.Add(ParseJson(item)); |
|||
} |
|||
|
|||
return array; |
|||
} |
|||
|
|||
default: |
|||
return JsonValue.Create(value); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue