mirror of https://github.com/Squidex/squidex.git
13 changed files with 164 additions and 39 deletions
@ -0,0 +1,73 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using GraphQL; |
||||
|
using Newtonsoft.Json.Linq; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Utils |
||||
|
{ |
||||
|
public static class InputConverter |
||||
|
{ |
||||
|
public static Inputs ToInputs(JObject input) |
||||
|
{ |
||||
|
var result = new Inputs(); |
||||
|
|
||||
|
if (input != null) |
||||
|
{ |
||||
|
foreach (var kvp in input) |
||||
|
{ |
||||
|
result.Add(kvp.Key, GetValue(kvp.Value, 1)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
private static object GetValue(object value, int level) |
||||
|
{ |
||||
|
if (level == 3) |
||||
|
{ |
||||
|
return value; |
||||
|
} |
||||
|
|
||||
|
switch (value) |
||||
|
{ |
||||
|
case JObject jObject: |
||||
|
{ |
||||
|
var result = new Dictionary<string, object>(); |
||||
|
|
||||
|
foreach (var kvp in jObject) |
||||
|
{ |
||||
|
result.Add(kvp.Key, GetValue(kvp.Value, level + 1)); |
||||
|
} |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
case JArray jArray: |
||||
|
{ |
||||
|
var result = new List<object>(); |
||||
|
|
||||
|
foreach (var item in jArray) |
||||
|
{ |
||||
|
result.Add(GetValue(item, level + 1)); |
||||
|
} |
||||
|
|
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
case JValue jValue: |
||||
|
{ |
||||
|
return jValue.Value; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return value; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using GraphQL.Language.AST; |
||||
|
using GraphQL.Types; |
||||
|
using Newtonsoft.Json.Linq; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Utils |
||||
|
{ |
||||
|
public sealed class JTokenConverter : IAstFromValueConverter |
||||
|
{ |
||||
|
public static readonly JTokenConverter Instance = new JTokenConverter(); |
||||
|
|
||||
|
private JTokenConverter() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public IValue Convert(object value, IGraphType type) |
||||
|
{ |
||||
|
return new JTokenValue(value as JToken); |
||||
|
} |
||||
|
|
||||
|
public bool Matches(object value, IGraphType type) |
||||
|
{ |
||||
|
return value is JToken; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using GraphQL.Language.AST; |
||||
|
using Newtonsoft.Json.Linq; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Utils |
||||
|
{ |
||||
|
public sealed class JTokenValue : ValueNode<JToken> |
||||
|
{ |
||||
|
public JTokenValue(JToken value) |
||||
|
{ |
||||
|
Value = value; |
||||
|
} |
||||
|
|
||||
|
protected override bool Equals(ValueNode<JToken> node) |
||||
|
{ |
||||
|
return node.Value.Equals(Value); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue