Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
hyzx86 committed Mar 19, 2024
1 parent 34877f5 commit 1571457
Showing 1 changed file with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,60 @@ namespace OrchardCore.Apis.GraphQL.Json;
public class GraphQLNamedQueryRequestJsonConverter : JsonConverter<GraphQLNamedQueryRequest>
{
public static readonly GraphQLNamedQueryRequestJsonConverter Instance = new();

/// <summary>
/// Name for the operation name parameter.
/// See https://github.com/graphql/graphql-over-http/blob/master/spec/GraphQLOverHTTP.md#request-parameters
/// </summary>
private const string OperationNameKey = "operationName";
private const string _operationNameKey = "operationName";

/// <summary>
/// Name for the query parameter.
/// See https://github.com/graphql/graphql-over-http/blob/master/spec/GraphQLOverHTTP.md#request-parameters
/// </summary>
private const string QueryKey = "query";
private const string _queryKey = "query";

/// <summary>
/// Name for the variables parameter.
/// See https://github.com/graphql/graphql-over-http/blob/master/spec/GraphQLOverHTTP.md#request-parameters
/// </summary>
private const string VariablesKey = "variables";
private const string _variablesKey = "variables";

/// <summary>
/// Name for the extensions parameter.
/// See https://github.com/graphql/graphql-over-http/blob/master/spec/GraphQLOverHTTP.md#request-parameters
/// </summary>
private const string ExtensionsKey = "extensions";
private const string _extensionsKey = "extensions";

private const string NamedQueryKey = "namedQuery";
private const string _namedQueryKey = "namedQuery";


public override void Write(Utf8JsonWriter writer, GraphQLNamedQueryRequest value, JsonSerializerOptions options)
{
writer.WriteStartObject();
if (value.Query != null)
{
writer.WritePropertyName(QueryKey);
writer.WritePropertyName(_queryKey);
writer.WriteStringValue(value.Query);
}
if (value.OperationName != null)
{
writer.WritePropertyName(OperationNameKey);
writer.WritePropertyName(_operationNameKey);
writer.WriteStringValue(value.OperationName);
}
if (value.Variables != null)
{
writer.WritePropertyName(VariablesKey);
writer.WritePropertyName(_variablesKey);
JsonSerializer.Serialize(writer, value.Variables, options);
}
if (value.Extensions != null)
{
writer.WritePropertyName(ExtensionsKey);
writer.WritePropertyName(_extensionsKey);
JsonSerializer.Serialize(writer, value.Extensions, options);
}
if (value.NamedQuery != null)
{
writer.WritePropertyName(NamedQueryKey);
writer.WritePropertyName(_namedQueryKey);
JsonSerializer.Serialize(writer, value.NamedQuery, options);
}
writer.WriteEndObject();
Expand Down Expand Up @@ -94,19 +94,19 @@ public override GraphQLNamedQueryRequest Read(ref Utf8JsonReader reader, Type ty

switch (key)
{
case QueryKey:
case _queryKey:
request.Query = reader.GetString()!;
break;
case OperationNameKey:
case _operationNameKey:
request.OperationName = reader.GetString()!;
break;
case NamedQueryKey:
case _namedQueryKey:
request.NamedQuery = reader.GetString();
break;
case VariablesKey:
case _variablesKey:
request.Variables = JsonSerializer.Deserialize<Inputs>(ref reader, options);
break;
case ExtensionsKey:
case _extensionsKey:
request.Extensions = JsonSerializer.Deserialize<Inputs>(ref reader, options);
break;
default:
Expand Down

0 comments on commit 1571457

Please sign in to comment.