mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-21 12:06:59 +01:00
Simpler class for string based scalars
This commit is contained in:
@@ -1,14 +1,11 @@
|
||||
using System;
|
||||
|
||||
using HotChocolate.Language;
|
||||
using HotChocolate.Types;
|
||||
|
||||
namespace Tgstation.Server.Host.GraphQL.Scalars
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="ScalarType{TRuntimeType, TLiteral}"/> for encoded JSON Web Tokens.
|
||||
/// A <see cref="StringScalarType"/> for encoded JSON Web Tokens.
|
||||
/// </summary>
|
||||
public sealed class JwtType : ScalarType<string, StringValueNode>
|
||||
public sealed class JwtType : StringScalarType
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="JwtType"/> class.
|
||||
@@ -19,20 +16,5 @@ namespace Tgstation.Server.Host.GraphQL.Scalars
|
||||
Description = "Represents an encoded JSON Web Token";
|
||||
SpecifiedBy = new Uri("https://datatracker.ietf.org/doc/html/rfc7519");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override IValueNode ParseResult(object? resultValue)
|
||||
=> ParseValue(resultValue);
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override string ParseLiteral(StringValueNode valueSyntax)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(valueSyntax);
|
||||
return valueSyntax.Value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override StringValueNode ParseValue(string runtimeValue)
|
||||
=> new(runtimeValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
|
||||
using HotChocolate.Language;
|
||||
using HotChocolate.Types;
|
||||
|
||||
namespace Tgstation.Server.Host.GraphQL.Scalars
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="ScalarType{TRuntimeType, TLiteral}"/> for specialized <see cref="string"/> types.
|
||||
/// </summary>
|
||||
public abstract class StringScalarType : ScalarType<string, StringValueNode>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StringScalarType"/> class.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the GraphQL scalar type.</param>
|
||||
public StringScalarType(string name)
|
||||
: base(name)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override IValueNode ParseResult(object? resultValue)
|
||||
=> ParseValue(resultValue);
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override string ParseLiteral(StringValueNode valueSyntax)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(valueSyntax);
|
||||
return valueSyntax.Value;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override StringValueNode ParseValue(string runtimeValue)
|
||||
=> new(runtimeValue);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user