Skip to content

Commit

Permalink
Merge branch 'develop' into vbornand-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Oct 16, 2020
2 parents e1560c7 + 8ceda1a commit 6d355dc
Show file tree
Hide file tree
Showing 96 changed files with 3,211 additions and 430 deletions.
2 changes: 1 addition & 1 deletion src/HotChocolate/Core/src/Abstractions/Execution/IQuery.cs
Expand Up @@ -6,7 +6,7 @@
namespace HotChocolate.Execution
{
/// <summary>
/// Represent a executable query.
/// Represents an executable query.
/// </summary>
public interface IQuery
{
Expand Down
12 changes: 12 additions & 0 deletions src/HotChocolate/Core/src/Abstractions/IExecutable.cs
@@ -0,0 +1,12 @@
using System.Threading;
using System.Threading.Tasks;

namespace HotChocolate
{
public interface IExecutable
{
ValueTask<object> ExecuteAsync(CancellationToken cancellationToken);

string Print();
}
}
11 changes: 11 additions & 0 deletions src/HotChocolate/Core/src/Abstractions/IExecutable~1.cs
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace HotChocolate
{
public interface IExecutable<T> : IExecutable
{
new ValueTask<IReadOnlyList<T>> ExecuteAsync(CancellationToken cancellationToken);
}
}
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using static HotChocolate.Execution.Properties.Resources;

namespace HotChocolate.Execution
{
Expand Down Expand Up @@ -38,7 +39,7 @@ public static class ExecutionRequestExecutorExtensions
if (string.IsNullOrEmpty(query))
{
throw new ArgumentException(
"The query mustn't be null or empty.",
ExecutionRequestExecutorExtensions_ExecuteAsync_QueryCannotBeNullOrEmpty,
nameof(query));
}

Expand All @@ -60,7 +61,7 @@ public static class ExecutionRequestExecutorExtensions
if (string.IsNullOrEmpty(query))
{
throw new ArgumentException(
"The query mustn't be null or empty.",
ExecutionRequestExecutorExtensions_ExecuteAsync_QueryCannotBeNullOrEmpty,
nameof(query));
}

Expand All @@ -82,7 +83,7 @@ public static class ExecutionRequestExecutorExtensions
if (string.IsNullOrEmpty(query))
{
throw new ArgumentException(
"The query mustn't be null or empty.",
ExecutionRequestExecutorExtensions_ExecuteAsync_QueryCannotBeNullOrEmpty,
nameof(query));
}

Expand Down Expand Up @@ -113,7 +114,7 @@ public static class ExecutionRequestExecutorExtensions
if (string.IsNullOrEmpty(query))
{
throw new ArgumentException(
"The query mustn't be null or empty.",
ExecutionRequestExecutorExtensions_ExecuteAsync_QueryCannotBeNullOrEmpty,
nameof(query));
}

Expand Down Expand Up @@ -163,7 +164,7 @@ public static class ExecutionRequestExecutorExtensions
if (string.IsNullOrEmpty(query))
{
throw new ArgumentException(
"The query mustn't be null or empty.",
ExecutionRequestExecutorExtensions_ExecuteAsync_QueryCannotBeNullOrEmpty,
nameof(query));
}

Expand All @@ -186,7 +187,7 @@ public static class ExecutionRequestExecutorExtensions
if (string.IsNullOrEmpty(query))
{
throw new ArgumentException(
"The query mustn't be null or empty.",
ExecutionRequestExecutorExtensions_ExecuteAsync_QueryCannotBeNullOrEmpty,
nameof(query));
}

Expand Down
Expand Up @@ -8,15 +8,36 @@ internal static class ArgumentNonNullValidator
{
public static ValidationResult Validate(IInputField field, IValueNode? value, Path path)
{
if (value.IsNull())
// if no value was provided
if (value is null)
{
// the type is a non-null type and no default value has been set we mark this
// field as violation.
if (field.Type.IsNonNullType() && field.DefaultValue.IsNull())
{
return new ValidationResult(field.Type, path);
}

// if the field has a default value or nullable everything is fine and we
// return success.
return default;
}

// if null was explicitly set
if (value is NullValueNode)
{
// and the field type is a non-null type we will mark the field value
// as violation.
if (field.Type.IsNonNullType())
{
return new ValidationResult(field.Type, path);
}

// if the field is nullable we will mark the field as valid.
return default;
}

// if the field has a value we traverse it and make sure the value is correct.
return ValidateInnerType(field.Type, value, path);
}

Expand All @@ -40,10 +61,8 @@ private static ValidationResult ValidateInnerType(IType type, IValueNode? value,
{
return ValidateList(listType, listValue, path);
}
else
{
Validate(listType.ElementType, value, path);
}

Validate(listType.ElementType, value, path);
}

if (innerType is InputObjectType inputType && value is ObjectValueNode ov)
Expand All @@ -61,7 +80,7 @@ private static ValidationResult ValidateInnerType(IType type, IValueNode? value,
{
var fields = new Dictionary<NameString, IValueNode>();

for (int i = 0; i < value.Fields.Count; i++)
for (var i = 0; i < value.Fields.Count; i++)
{
ObjectFieldNode field = value.Fields[i];
fields[field.Name.Value] = field.Value;
Expand All @@ -88,7 +107,7 @@ private static ValidationResult ValidateInnerType(IType type, IValueNode? value,
private static ValidationResult ValidateList(ListType type, ListValueNode list, Path path)
{
IType elementType = type.ElementType();
int i = 0;
var i = 0;

foreach (IValueNode element in list.Items)
{
Expand Down
Expand Up @@ -66,6 +66,10 @@ private async ValueTask ExecuteResolverPipelineAsync()

switch (_context.Result)
{
case IExecutable executable:
_context.Result = await executable.ExecuteAsync(_context.RequestAborted);
break;

case IQueryable queryable:
_context.Result = await Task.Run(() =>
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/HotChocolate/Core/src/Execution/Properties/Resources.resx
Expand Up @@ -237,4 +237,7 @@
<data name="OperationCompiler_Compile_SelectionSetIsEmpty" xml:space="preserve">
<value>The operation selection set is empty.</value>
</data>
<data name="ExecutionRequestExecutorExtensions_ExecuteAsync_QueryCannotBeNullOrEmpty" xml:space="preserve">
<value>The query cannot be null or empty.</value>
</data>
</root>
Expand Up @@ -194,6 +194,13 @@ private static void WritePath(Utf8JsonWriter writer, Path? path)

private static void WritePathValue(Utf8JsonWriter writer, Path path)
{
if (path is RootPathSegment)
{
writer.WriteStartArray();
writer.WriteEndArray();
return;
}

writer.WriteStartArray();

IReadOnlyList<object> list = path.ToList();
Expand Down Expand Up @@ -400,7 +407,7 @@ private static void WritePathValue(Utf8JsonWriter writer, Path path)
break;

case Path p:
WritePath(writer, p);
WritePathValue(writer, p);
break;

default:
Expand Down
Expand Up @@ -13,6 +13,7 @@ internal sealed class SyntaxTypeReferenceHandler
: ITypeRegistrarHandler
{
private readonly ITypeInspector _typeInspector;
private readonly HashSet<string> _handled = new HashSet<string>();

public SyntaxTypeReferenceHandler(ITypeInspector typeInspector)
{
Expand All @@ -26,9 +27,9 @@ public SyntaxTypeReferenceHandler(ITypeInspector typeInspector)
foreach (SyntaxTypeReference typeReference in
typeReferences.OfType<SyntaxTypeReference>())
{
if (Scalars.TryGetScalar(
typeReference.Type.NamedType().Name.Value,
out Type? scalarType))
string name = typeReference.Type.NamedType().Name.Value;
if (_handled.Add(name) &&
Scalars.TryGetScalar(name, out Type? scalarType))
{
ExtendedTypeReference namedTypeReference =
_typeInspector.GetTypeRef(scalarType);
Expand Down
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using HotChocolate.Language;
using HotChocolate.Properties;
using HotChocolate.Types;
using HotChocolate.Types.Descriptors;
Expand Down Expand Up @@ -109,7 +110,7 @@ public IReadOnlyList<ISchemaError> DiscoverTypes()

if (_errors.Count == 0)
{
_typeRegistry.CompleteDiscovery();
_typeRegistry.CompleteDiscovery();
}

return _errors;
Expand Down Expand Up @@ -190,7 +191,7 @@ private void CollectErrors()
{
builder.SetTypeSystemObject(types[0].Type);
}
else if(types.Count > 1)
else if (types.Count > 1)
{
builder
.SetTypeSystemObject(types[0].Type)
Expand Down
11 changes: 11 additions & 0 deletions src/HotChocolate/Core/src/Types/Configuration/TypeRegistry.cs
Expand Up @@ -149,6 +149,17 @@ public void Register(RegisteredType registeredType)
}
}

public void Register(NameString typeName, ExtendedTypeReference typeReference)
{
if (typeReference is null)
{
throw new ArgumentNullException(nameof(typeReference));
}

typeName.EnsureNotEmpty(nameof(typeName));
_nameRefs[typeName] = typeReference;
}

public void Register(NameString typeName, RegisteredType registeredType)
{
if (registeredType is null)
Expand Down
Expand Up @@ -166,7 +166,8 @@ public static bool IsSupportedCollectionInterface(Type type)
|| typeDefinition == typeof(ImmutableList<>)
|| typeDefinition == typeof(ImmutableQueue<>)
|| typeDefinition == typeof(ImmutableStack<>)
|| typeDefinition == typeof(ImmutableHashSet<>))
|| typeDefinition == typeof(ImmutableHashSet<>)
|| typeDefinition == typeof(IExecutable<>))
{
return true;
}
Expand Down
Expand Up @@ -40,7 +40,8 @@ public static ExtendedMethodInfo FromMethod(MethodInfo method, TypeCache cache)
method,
() => Rewrite(
CreateExtendedType(context, helper.GetFlags(method), method.ReturnType),
method, cache));
method,
cache));

ParameterInfo[] parameters = method.GetParameters();
var parameterTypes = new Dictionary<ParameterInfo, IExtendedType>();
Expand Down Expand Up @@ -203,6 +204,7 @@ public static ExtendedMethodInfo FromMethod(MethodInfo method, TypeCache cache)
state = flags[0];
}
}

return state;
}
}
Expand Down
Expand Up @@ -20,7 +20,7 @@ private static ExtendedType FromTypeInternal(Type type, TypeCache cache)
&& type.GetGenericTypeDefinition() == typeof(Nullable<>))
{
Type inner = type.GetGenericArguments()[0];

return new ExtendedType(
inner,
ExtendedTypeKind.Runtime,
Expand Down Expand Up @@ -50,7 +50,7 @@ private static ExtendedType FromTypeInternal(Type type, TypeCache cache)
}

public static IReadOnlyList<ExtendedType> GetGenericArguments(
Type type,
Type type,
TypeCache cache)
{
if (type.IsGenericType)
Expand Down
4 changes: 3 additions & 1 deletion src/HotChocolate/Core/src/Types/SchemaBuilder.Setup.cs
Expand Up @@ -112,10 +112,12 @@ public static Schema Create(SchemaBuilder builder)
builder,
OperationType.Query,
visitor.QueryTypeName);

RegisterOperationName(
builder,
OperationType.Mutation,
visitor.MutationTypeName);

RegisterOperationName(
builder,
OperationType.Subscription,
Expand Down Expand Up @@ -334,7 +336,7 @@ public static Schema Create(SchemaBuilder builder)

Dictionary<OperationType, ITypeReference> operations =
builder._operations.ToDictionary(
t => t.Key,
t => t.Key,
t => t.Value(context.TypeInspector));

definition.QueryType = ResolveOperation(
Expand Down
Expand Up @@ -7,24 +7,10 @@ public abstract class FieldDefinitionBase
: DefinitionBase
, IHasDirectiveDefinition
{
private ITypeReference type;

/// <summary>
/// Gets the field type.
/// </summary>
public ITypeReference Type
{
get => type;
set
{
if(type is ExtendedTypeReference r &&
r.Type.Kind == ExtendedTypeKind.Extended)
{

}
type = value;
}
}
public ITypeReference Type { get; set; }

/// <summary>
/// Defines if this field is ignored and will
Expand Down

0 comments on commit 6d355dc

Please sign in to comment.