in src/Config/Converters/GraphQLRuntimeOptionsConverterFactory.cs [46:179]
public override GraphQLRuntimeOptions? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.True || reader.TokenType == JsonTokenType.Null)
{
return new GraphQLRuntimeOptions();
}
if (reader.TokenType == JsonTokenType.False)
{
return new GraphQLRuntimeOptions(Enabled: false);
}
if (reader.TokenType == JsonTokenType.StartObject)
{
// Initialize with Multiple Mutation operations disabled by default
GraphQLRuntimeOptions graphQLRuntimeOptions = new();
MultipleMutationOptionsConverter multipleMutationOptionsConverter = options.GetConverter(typeof(MultipleMutationOptions)) as MultipleMutationOptionsConverter ??
throw new JsonException("Failed to get multiple mutation options converter");
while (reader.Read())
{
if (reader.TokenType == JsonTokenType.EndObject)
{
break;
}
string? propertyName = reader.GetString();
if (propertyName is null)
{
throw new JsonException("Invalid property : null");
}
reader.Read();
switch (propertyName)
{
case "enabled":
if (reader.TokenType is JsonTokenType.True || reader.TokenType is JsonTokenType.False)
{
graphQLRuntimeOptions = graphQLRuntimeOptions with { Enabled = reader.GetBoolean() };
}
else
{
throw new JsonException($"Unsupported value entered for the property 'enabled': {reader.TokenType}");
}
break;
case "allow-introspection":
if (reader.TokenType is JsonTokenType.True || reader.TokenType is JsonTokenType.False)
{
graphQLRuntimeOptions = graphQLRuntimeOptions with { AllowIntrospection = reader.GetBoolean() };
}
else
{
throw new JsonException($"Unexpected type of value entered for allow-introspection: {reader.TokenType}");
}
break;
case "enable-aggregation":
if (reader.TokenType is JsonTokenType.True || reader.TokenType is JsonTokenType.False)
{
graphQLRuntimeOptions = graphQLRuntimeOptions with { EnableAggregation = reader.GetBoolean() };
}
else
{
throw new JsonException($"Unexpected type of value entered for enable-aggregation: {reader.TokenType}");
}
break;
case "path":
if (reader.TokenType is JsonTokenType.String)
{
string? path = reader.DeserializeString(_replaceEnvVar);
if (path is null)
{
path = "/graphql";
}
graphQLRuntimeOptions = graphQLRuntimeOptions with { Path = path };
}
else
{
throw new JsonException($"Unexpected type of value entered for path: {reader.TokenType}");
}
break;
case "multiple-mutations":
graphQLRuntimeOptions = graphQLRuntimeOptions with { MultipleMutationOptions = multipleMutationOptionsConverter.Read(ref reader, typeToConvert, options) };
break;
case "depth-limit":
if (reader.TokenType is JsonTokenType.Null)
{
graphQLRuntimeOptions = graphQLRuntimeOptions with { DepthLimit = null, UserProvidedDepthLimit = true };
}
else if (reader.TokenType is JsonTokenType.Number)
{
int depthLimit;
try
{
depthLimit = reader.GetInt32();
}
catch (FormatException)
{
throw new JsonException($"The JSON token value is of the incorrect numeric format.");
}
if (depthLimit < -1 || depthLimit == 0)
{
throw new JsonException($"Invalid depth-limit: {depthLimit}. Specify a depth limit > 0 or remove the existing depth limit by specifying -1.");
}
graphQLRuntimeOptions = graphQLRuntimeOptions with { DepthLimit = depthLimit, UserProvidedDepthLimit = true };
}
else
{
throw new JsonException($"Unsupported value entered for depth-limit: {reader.TokenType}");
}
break;
default:
throw new JsonException($"Unexpected property {propertyName}");
}
}
return graphQLRuntimeOptions;
}
throw new JsonException("Failed to read the GraphQL Runtime Options");
}