mirror of https://github.com/Squidex/squidex.git
1 changed files with 55 additions and 0 deletions
@ -0,0 +1,55 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using GraphQL.Language.AST; |
|||
using GraphQL.Types; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Utils |
|||
{ |
|||
public sealed class GuidGraphType2 : ScalarGraphType |
|||
{ |
|||
public GuidGraphType2() |
|||
{ |
|||
Name = "Guid"; |
|||
|
|||
Description = "The `Guid` scalar type global unique identifier"; |
|||
} |
|||
|
|||
public override object Serialize(object value) |
|||
{ |
|||
return ParseValue(value)?.ToString(); |
|||
} |
|||
|
|||
public override object ParseValue(object value) |
|||
{ |
|||
if (value is Guid guid) |
|||
{ |
|||
return guid; |
|||
} |
|||
|
|||
var inputValue = value?.ToString().Trim('"'); |
|||
|
|||
if (Guid.TryParse(inputValue, out guid)) |
|||
{ |
|||
return guid; |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
public override object ParseLiteral(IValue value) |
|||
{ |
|||
if (value is StringValue stringValue) |
|||
{ |
|||
return ParseValue(stringValue.Value); |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue