-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Roll back exposed GraphQL API changes by adding LegacyBencodexValueType
- Loading branch information
1 parent
1b34825
commit f12184e
Showing
3 changed files
with
57 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using Bencodex; | ||
using GraphQL.Language.AST; | ||
using GraphQL.Types; | ||
using Libplanet.Common; | ||
|
||
namespace Libplanet.Explorer.GraphTypes | ||
{ | ||
public class LegacyBencodexValueType : StringGraphType | ||
{ | ||
private static readonly Codec _codec = new(); | ||
|
||
public LegacyBencodexValueType() | ||
{ | ||
Name = "BencodexValue"; | ||
} | ||
|
||
public override object? Serialize(object? value) | ||
{ | ||
if (value is Bencodex.Types.IValue iv) | ||
{ | ||
return _codec.Encode(iv); | ||
} | ||
|
||
return value; | ||
} | ||
|
||
public override object? ParseValue(object? value) | ||
{ | ||
return value switch | ||
{ | ||
null => null, | ||
string hex => _codec.Decode(ByteUtil.ParseHex(hex)), | ||
_ => throw new ArgumentException( | ||
$"Expected a hexadecimal string but {value}", | ||
nameof(value) | ||
), | ||
}; | ||
} | ||
|
||
public override object? ParseLiteral(IValue? value) | ||
{ | ||
if (value is StringValue) | ||
{ | ||
return ParseValue(value.Value); | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters