-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3579 from greymistcube/refactor/roll-back-changes…
…-for-old-queries ♻️ ⏪ Revert changes for old queries
- Loading branch information
Showing
4 changed files
with
62 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
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 = "LegacyBencodexValue"; | ||
} | ||
|
||
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