diff --git a/src/HotChocolate/Core/src/Abstractions/Execution/IQuery.cs b/src/HotChocolate/Core/src/Abstractions/Execution/IQuery.cs
index 9590075e8f0..21bac84ba4d 100644
--- a/src/HotChocolate/Core/src/Abstractions/Execution/IQuery.cs
+++ b/src/HotChocolate/Core/src/Abstractions/Execution/IQuery.cs
@@ -6,7 +6,7 @@
namespace HotChocolate.Execution
{
///
- /// Represent a executable query.
+ /// Represents an executable query.
///
public interface IQuery
{
diff --git a/src/HotChocolate/Core/src/Types/Configuration/SyntaxTypeReferenceHandler.cs b/src/HotChocolate/Core/src/Types/Configuration/SyntaxTypeReferenceHandler.cs
index 861619047dd..0242cfd0cf6 100644
--- a/src/HotChocolate/Core/src/Types/Configuration/SyntaxTypeReferenceHandler.cs
+++ b/src/HotChocolate/Core/src/Types/Configuration/SyntaxTypeReferenceHandler.cs
@@ -13,6 +13,7 @@ internal sealed class SyntaxTypeReferenceHandler
: ITypeRegistrarHandler
{
private readonly ITypeInspector _typeInspector;
+ private readonly HashSet _handled = new HashSet();
public SyntaxTypeReferenceHandler(ITypeInspector typeInspector)
{
@@ -26,9 +27,9 @@ public SyntaxTypeReferenceHandler(ITypeInspector typeInspector)
foreach (SyntaxTypeReference typeReference in
typeReferences.OfType())
{
- 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);
diff --git a/src/HotChocolate/Core/src/Types/Configuration/TypeDiscoverer.cs b/src/HotChocolate/Core/src/Types/Configuration/TypeDiscoverer.cs
index 9e909963c14..22815a27bc0 100644
--- a/src/HotChocolate/Core/src/Types/Configuration/TypeDiscoverer.cs
+++ b/src/HotChocolate/Core/src/Types/Configuration/TypeDiscoverer.cs
@@ -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;
@@ -109,7 +110,7 @@ public IReadOnlyList DiscoverTypes()
if (_errors.Count == 0)
{
- _typeRegistry.CompleteDiscovery();
+ _typeRegistry.CompleteDiscovery();
}
return _errors;
@@ -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)
diff --git a/src/HotChocolate/Core/src/Types/Configuration/TypeRegistry.cs b/src/HotChocolate/Core/src/Types/Configuration/TypeRegistry.cs
index 9c55a310b32..90e3494c932 100644
--- a/src/HotChocolate/Core/src/Types/Configuration/TypeRegistry.cs
+++ b/src/HotChocolate/Core/src/Types/Configuration/TypeRegistry.cs
@@ -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)
diff --git a/src/HotChocolate/Core/src/Types/SchemaBuilder.Setup.cs b/src/HotChocolate/Core/src/Types/SchemaBuilder.Setup.cs
index a1e8cf0e3a7..14810c4363f 100644
--- a/src/HotChocolate/Core/src/Types/SchemaBuilder.Setup.cs
+++ b/src/HotChocolate/Core/src/Types/SchemaBuilder.Setup.cs
@@ -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,
@@ -334,7 +336,7 @@ public static Schema Create(SchemaBuilder builder)
Dictionary operations =
builder._operations.ToDictionary(
- t => t.Key,
+ t => t.Key,
t => t.Value(context.TypeInspector));
definition.QueryType = ResolveOperation(
diff --git a/src/HotChocolate/Core/src/Types/Types/Descriptors/Definitions/FieldDefinitionBase.cs b/src/HotChocolate/Core/src/Types/Types/Descriptors/Definitions/FieldDefinitionBase.cs
index 3c92e058981..ab6ae11d5c2 100644
--- a/src/HotChocolate/Core/src/Types/Types/Descriptors/Definitions/FieldDefinitionBase.cs
+++ b/src/HotChocolate/Core/src/Types/Types/Descriptors/Definitions/FieldDefinitionBase.cs
@@ -7,24 +7,10 @@ public abstract class FieldDefinitionBase
: DefinitionBase
, IHasDirectiveDefinition
{
- private ITypeReference type;
-
///
/// Gets the field type.
///
- public ITypeReference Type
- {
- get => type;
- set
- {
- if(type is ExtendedTypeReference r &&
- r.Type.Kind == ExtendedTypeKind.Extended)
- {
-
- }
- type = value;
- }
- }
+ public ITypeReference Type { get; set; }
///
/// Defines if this field is ignored and will
diff --git a/src/HotChocolate/Core/src/Types/Types/Factories/ObjectTypeFactory.cs b/src/HotChocolate/Core/src/Types/Types/Factories/ObjectTypeFactory.cs
index 5c643e997e2..3b9cef6db42 100644
--- a/src/HotChocolate/Core/src/Types/Types/Factories/ObjectTypeFactory.cs
+++ b/src/HotChocolate/Core/src/Types/Types/Factories/ObjectTypeFactory.cs
@@ -4,6 +4,8 @@
using HotChocolate.Configuration;
using HotChocolate.Language;
+#nullable enable
+
namespace HotChocolate.Types.Factories
{
internal sealed class ObjectTypeFactory
@@ -34,8 +36,7 @@ internal sealed class ObjectTypeFactory
if (bindingInfo.SourceType != null)
{
- d.Extend().OnBeforeCreate(
- t => t.RuntimeType = bindingInfo.SourceType);
+ d.Extend().OnBeforeCreate(t => t.RuntimeType = bindingInfo.SourceType);
}
foreach (DirectiveNode directive in node.Directives)
@@ -91,10 +92,10 @@ internal sealed class ObjectTypeFactory
}
}
- string deprecactionReason = fieldDefinition.DeprecationReason();
- if (!string.IsNullOrEmpty(deprecactionReason))
+ string deprecationReason = fieldDefinition.DeprecationReason();
+ if (!string.IsNullOrEmpty(deprecationReason))
{
- fieldDescriptor.Deprecated(deprecactionReason);
+ fieldDescriptor.Deprecated(deprecationReason);
}
DeclareFieldArguments(fieldDescriptor, fieldDefinition);
@@ -112,8 +113,7 @@ internal sealed class ObjectTypeFactory
a =>
{
IArgumentDescriptor descriptor = a
- .Description(
- inputFieldDefinition.Description?.Value)
+ .Description(inputFieldDefinition.Description?.Value)
.Type(inputFieldDefinition.Type)
.DefaultValue(inputFieldDefinition.DefaultValue)
.SyntaxNode(inputFieldDefinition);
diff --git a/src/HotChocolate/Core/src/Types/Types/Factories/UnionTypeFactory.cs b/src/HotChocolate/Core/src/Types/Types/Factories/UnionTypeFactory.cs
index ad402be7445..02024b93f6b 100644
--- a/src/HotChocolate/Core/src/Types/Types/Factories/UnionTypeFactory.cs
+++ b/src/HotChocolate/Core/src/Types/Types/Factories/UnionTypeFactory.cs
@@ -32,8 +32,7 @@ internal sealed class UnionTypeFactory
if (bindingInfo.SourceType != null)
{
- d.Extend().OnBeforeCreate(
- t => t.RuntimeType = bindingInfo.SourceType);
+ d.Extend().OnBeforeCreate(t => t.RuntimeType = bindingInfo.SourceType);
}
foreach (NamedTypeNode namedType in node.Types)
diff --git a/src/HotChocolate/Core/src/Types/Types/Helpers/TypeDependencyHelper.cs b/src/HotChocolate/Core/src/Types/Types/Helpers/TypeDependencyHelper.cs
index b989c436702..22699a35b68 100644
--- a/src/HotChocolate/Core/src/Types/Types/Helpers/TypeDependencyHelper.cs
+++ b/src/HotChocolate/Core/src/Types/Types/Helpers/TypeDependencyHelper.cs
@@ -126,7 +126,7 @@ internal static class TypeDependencyHelper
{
RegisterAdditionalDependencies(context, field);
- if (field.Type != null)
+ if (field.Type is not null)
{
context.RegisterDependency(field.Type,
TypeDependencyKind.Default);
@@ -158,13 +158,13 @@ internal static class TypeDependencyHelper
private static void RegisterFieldDependencies(
this ITypeDiscoveryContext context,
- IEnumerable fields)
+ IReadOnlyList fields)
{
foreach (OutputFieldDefinitionBase field in fields)
{
RegisterAdditionalDependencies(context, field);
- if (field.Type != null)
+ if (field.Type is not null)
{
context.RegisterDependency(field.Type,
TypeDependencyKind.Default);
@@ -173,10 +173,10 @@ internal static class TypeDependencyHelper
context.RegisterDependencyRange(
field.Directives.Select(t => t.TypeReference),
TypeDependencyKind.Completed);
-
- RegisterFieldDependencies(context,
- fields.SelectMany(t => t.Arguments).ToList());
}
+
+ RegisterFieldDependencies(context,
+ fields.SelectMany(t => t.Arguments));
}
private static void RegisterFieldDependencies(
@@ -187,7 +187,7 @@ internal static class TypeDependencyHelper
{
RegisterAdditionalDependencies(context, field);
- if (field.Type != null)
+ if (field.Type is not null)
{
context.RegisterDependency(field.Type,
TypeDependencyKind.Completed);
diff --git a/src/HotChocolate/Core/src/Types/Types/ObjectType.cs b/src/HotChocolate/Core/src/Types/Types/ObjectType.cs
index f661f686fa4..837958a6881 100644
--- a/src/HotChocolate/Core/src/Types/Types/ObjectType.cs
+++ b/src/HotChocolate/Core/src/Types/Types/ObjectType.cs
@@ -6,6 +6,7 @@
using HotChocolate.Resolvers;
using HotChocolate.Types.Descriptors;
using HotChocolate.Types.Descriptors.Definitions;
+using static HotChocolate.Utilities.ErrorHelper;
#nullable enable
@@ -133,21 +134,7 @@ private void CompleteIsOfType(ITypeCompletionContext context)
foreach (ObjectFieldDefinition field in invalidFields)
{
- // TODO : ErrorHelper
- context.ReportError(SchemaErrorBuilder.New()
- .SetMessage(
- "Unable to infer or resolve the type of " +
- "field {0}.{1}. Try to explicitly provide the " +
- "type like the following: " +
- "`descriptor.Field(\"field\")" +
- ".Type>()`.",
- Name,
- field.Name)
- .SetCode(ErrorCodes.Schema.NoFieldType)
- .SetTypeSystemObject(this)
- .SetPath(Path.New(Name).Append(field.Name))
- .SetExtension(TypeErrorFields.Definition, field)
- .Build());
+ context.ReportError(ObjectType_UnableToInferOrResolveType(Name, this, field));
}
return invalidFields.Length == 0;
diff --git a/src/HotChocolate/Core/src/Types/Types/Scalars/IntType.cs b/src/HotChocolate/Core/src/Types/Types/Scalars/IntType.cs
index f390e36eae7..8b8d5ac7d64 100644
--- a/src/HotChocolate/Core/src/Types/Types/Scalars/IntType.cs
+++ b/src/HotChocolate/Core/src/Types/Types/Scalars/IntType.cs
@@ -17,28 +17,28 @@ public sealed class IntType
: IntegerTypeBase
{
public IntType()
- : this(int.MinValue, int.MaxValue)
+ : this(ScalarNames.Int,
+ TypeResources.IntType_Description,
+ bind: BindingBehavior.Implicit)
{
}
public IntType(int min, int max)
- : this(ScalarNames.Int, min, max)
+ : this(ScalarNames.Int,
+ TypeResources.IntType_Description,
+ min,
+ max,
+ BindingBehavior.Implicit)
{
- Description = TypeResources.IntType_Description;
}
- public IntType(NameString name)
- : this(name, int.MinValue, int.MaxValue)
- {
- }
-
- public IntType(NameString name, int min, int max)
- : base(name, min, max, BindingBehavior.Implicit)
- {
- }
-
- public IntType(NameString name, string description, int min, int max)
- : base(name, min, max, BindingBehavior.Implicit)
+ public IntType(
+ NameString name,
+ string? description = null,
+ int min = int.MinValue,
+ int max = int.MaxValue,
+ BindingBehavior bind = BindingBehavior.Explicit)
+ : base(name, min, max, bind)
{
Description = description;
}
diff --git a/src/HotChocolate/Core/src/Types/Utilities/ErrorHelper.cs b/src/HotChocolate/Core/src/Types/Utilities/ErrorHelper.cs
index ebf8b300937..4a25fc72d6d 100644
--- a/src/HotChocolate/Core/src/Types/Utilities/ErrorHelper.cs
+++ b/src/HotChocolate/Core/src/Types/Utilities/ErrorHelper.cs
@@ -1,6 +1,7 @@
using HotChocolate.Language;
using HotChocolate.Properties;
using HotChocolate.Types;
+using HotChocolate.Types.Descriptors.Definitions;
#nullable enable
@@ -10,7 +11,7 @@ internal static class ErrorHelper
{
public static ISchemaError CompleteInterfacesHelper_UnableToResolveInterface(
ITypeSystemObject interfaceOrObject,
- ISyntaxNode? node)=>
+ ISyntaxNode? node)=>
SchemaErrorBuilder.New()
.SetMessage("COULD NOT RESOLVE INTERFACE")
.SetCode(ErrorCodes.Schema.MissingType)
@@ -38,7 +39,7 @@ internal static class ErrorHelper
Types.DirectiveLocation location,
ITypeSystemObject type,
DirectiveNode? syntaxNode,
- object source) =>
+ object source) =>
SchemaErrorBuilder.New()
.SetMessage(
TypeResources.DirectiveCollection_LocationNotAllowed,
@@ -55,7 +56,7 @@ internal static class ErrorHelper
ITypeSystemObject type,
DirectiveNode? syntaxNode,
object source,
- string argumentName) =>
+ string argumentName) =>
SchemaErrorBuilder.New()
.SetMessage(
"The argument `{0}` value type is wrong.",
@@ -101,5 +102,22 @@ internal static class ErrorHelper
.AddSyntaxNode(syntaxNode)
.SetExtension("Source", source)
.Build();
+
+ public static ISchemaError ObjectType_UnableToInferOrResolveType(
+ NameString typeName, ObjectType type, ObjectFieldDefinition field) =>
+ SchemaErrorBuilder.New()
+ .SetMessage(
+ "Unable to infer or resolve the type of " +
+ "field {0}.{1}. Try to explicitly provide the " +
+ "type like the following: " +
+ "`descriptor.Field(\"field\")" +
+ ".Type>()`.",
+ typeName,
+ field.Name)
+ .SetCode(ErrorCodes.Schema.NoFieldType)
+ .SetTypeSystemObject(type)
+ .SetPath(Path.New(typeName).Append(field.Name))
+ .SetExtension(TypeErrorFields.Definition, field)
+ .Build();
}
}
diff --git a/src/HotChocolate/Core/src/Validation/Rules/FragmentVisitor.cs b/src/HotChocolate/Core/src/Validation/Rules/FragmentVisitor.cs
index 54b9bed4449..09ee201cf1f 100644
--- a/src/HotChocolate/Core/src/Validation/Rules/FragmentVisitor.cs
+++ b/src/HotChocolate/Core/src/Validation/Rules/FragmentVisitor.cs
@@ -73,7 +73,7 @@ internal sealed class FragmentVisitor : TypeDocumentValidatorVisitor
{
context.Names.Clear();
- for (int i = 0; i < node.Definitions.Count; i++)
+ for (var i = 0; i < node.Definitions.Count; i++)
{
IDefinitionNode definition = node.Definitions[i];
if (definition.Kind == SyntaxKind.FragmentDefinition)
@@ -114,19 +114,18 @@ internal sealed class FragmentVisitor : TypeDocumentValidatorVisitor
{
return Skip;
}
- else if (context.Types.TryPeek(out IType type) &&
+
+ if (context.Types.TryPeek(out IType type) &&
type.NamedType() is IComplexOutputType ot &&
- ot.Fields.TryGetField(node.Name.Value, out IOutputField of))
+ ot.Fields.TryGetField(node.Name.Value, out IOutputField? of))
{
context.OutputFields.Push(of);
context.Types.Push(of.Type);
return Continue;
}
- else
- {
- context.UnexpectedErrorsDetected = true;
- return Skip;
- }
+
+ context.UnexpectedErrorsDetected = true;
+ return Skip;
}
protected override ISyntaxVisitorAction Leave(
@@ -157,17 +156,13 @@ internal sealed class FragmentVisitor : TypeDocumentValidatorVisitor
context.Types.Push(type);
return Continue;
}
- else
- {
- context.Errors.Add(context.FragmentOnlyCompositeType(node, type.NamedType()));
- return Skip;
- }
- }
- else
- {
- context.Errors.Add(context.FragmentTypeConditionUnknown(node, node.TypeCondition));
+
+ context.Errors.Add(context.FragmentOnlyCompositeType(node, type.NamedType()));
return Skip;
}
+
+ context.Errors.Add(context.FragmentTypeConditionUnknown(node, node.TypeCondition));
+ return Skip;
}
protected override ISyntaxVisitorAction Leave(
@@ -186,7 +181,8 @@ internal sealed class FragmentVisitor : TypeDocumentValidatorVisitor
{
return Continue;
}
- else if (context.Schema.TryGetType(
+
+ if (context.Schema.TryGetType(
node.TypeCondition.Name.Value,
out INamedOutputType type))
{
@@ -199,17 +195,13 @@ internal sealed class FragmentVisitor : TypeDocumentValidatorVisitor
context.Types.Push(type);
return Continue;
}
- else
- {
- context.Errors.Add(context.FragmentOnlyCompositeType(node, type.NamedType()));
- return Skip;
- }
- }
- else
- {
- context.Errors.Add(context.FragmentTypeConditionUnknown(node, node.TypeCondition));
+
+ context.Errors.Add(context.FragmentOnlyCompositeType(node, type.NamedType()));
return Skip;
}
+
+ context.Errors.Add(context.FragmentTypeConditionUnknown(node, node.TypeCondition));
+ return Skip;
}
protected override ISyntaxVisitorAction Enter(
diff --git a/src/HotChocolate/Core/src/Validation/Rules/ValueVisitor.cs b/src/HotChocolate/Core/src/Validation/Rules/ValueVisitor.cs
index 76b3bcd5182..a98c42b9648 100644
--- a/src/HotChocolate/Core/src/Validation/Rules/ValueVisitor.cs
+++ b/src/HotChocolate/Core/src/Validation/Rules/ValueVisitor.cs
@@ -60,7 +60,7 @@ public ValueVisitor()
if (context.Types.TryPeek(out IType type) &&
type.NamedType() is IComplexOutputType ot &&
- ot.Fields.TryGetField(node.Name.Value, out IOutputField of))
+ ot.Fields.TryGetField(node.Name.Value, out IOutputField? of))
{
context.OutputFields.Push(of);
context.Types.Push(of.Type);
@@ -131,7 +131,7 @@ public ValueVisitor()
{
if (context.Directives.TryPeek(out DirectiveType directive))
{
- if (directive.Arguments.TryGetField(node.Name.Value, out Argument argument))
+ if (directive.Arguments.TryGetField(node.Name.Value, out Argument? argument))
{
context.InputFields.Push(argument);
context.Types.Push(argument.Type);
@@ -143,7 +143,7 @@ public ValueVisitor()
if (context.OutputFields.TryPeek(out IOutputField field))
{
- if (field.Arguments.TryGetField(node.Name.Value, out IInputField argument))
+ if (field.Arguments.TryGetField(node.Name.Value, out IInputField? argument))
{
context.InputFields.Push(argument);
context.Types.Push(argument.Type);
@@ -221,7 +221,7 @@ public ValueVisitor()
{
if (context.Types.TryPeek(out IType type) &&
type.NamedType() is InputObjectType it &&
- it.Fields.TryGetField(node.Name.Value, out InputField field))
+ it.Fields.TryGetField(node.Name.Value, out InputField? field))
{
if (field.Type.IsNonNullType() &&
node.Value.IsNull())
diff --git a/src/HotChocolate/Core/test/Execution.Tests/AutoUpdateRequestExecutorProxyTests.cs b/src/HotChocolate/Core/test/Execution.Tests/AutoUpdateRequestExecutorProxyTests.cs
index 51023d82385..9d32f4490ac 100644
--- a/src/HotChocolate/Core/test/Execution.Tests/AutoUpdateRequestExecutorProxyTests.cs
+++ b/src/HotChocolate/Core/test/Execution.Tests/AutoUpdateRequestExecutorProxyTests.cs
@@ -60,8 +60,18 @@ public async Task Ensure_Executor_Is_Correctly_Swapped_When_Evicted()
// act
IRequestExecutor a = proxy.InnerExecutor;
resolver.EvictRequestExecutor();
- await Task.Delay(100);
+
+ var i = 0;
IRequestExecutor b = proxy.InnerExecutor;
+ while (ReferenceEquals(a, b))
+ {
+ await Task.Delay(100);
+ b = proxy.InnerExecutor;
+ if (i++ > 10)
+ {
+ break;
+ }
+ }
// assert
Assert.NotSame(a, b);
diff --git a/src/HotChocolate/Core/test/Validation.Tests/DocumentValidatorTests.cs b/src/HotChocolate/Core/test/Validation.Tests/DocumentValidatorTests.cs
index 40e528094a7..9f58cec5431 100644
--- a/src/HotChocolate/Core/test/Validation.Tests/DocumentValidatorTests.cs
+++ b/src/HotChocolate/Core/test/Validation.Tests/DocumentValidatorTests.cs
@@ -166,7 +166,7 @@ ... missingRequiredArg
}
",
t => Assert.Equal(
- $"The argument `nonNullBooleanArg` is required.",
+ "The argument `nonNullBooleanArg` is required.",
t.Message));
}
diff --git a/src/HotChocolate/Core/test/Validation.Tests/Types/QueryType.cs b/src/HotChocolate/Core/test/Validation.Tests/Types/QueryType.cs
index 824b412448b..42b684776cf 100644
--- a/src/HotChocolate/Core/test/Validation.Tests/Types/QueryType.cs
+++ b/src/HotChocolate/Core/test/Validation.Tests/Types/QueryType.cs
@@ -35,6 +35,10 @@ protected override void Configure(IObjectTypeDescriptor descriptor)
descriptor.Field(t => t.GetDogOrHuman())
.Type();
+
+ descriptor.Field("nonNull")
+ .Argument("a", a => a.Type>().DefaultValue("abc"))
+ .Resolve("foo");
}
}
}
diff --git a/src/HotChocolate/Core/test/Validation.Tests/ValuesOfCorrectTypeRuleTests.cs b/src/HotChocolate/Core/test/Validation.Tests/ValuesOfCorrectTypeRuleTests.cs
index 0ae7921af17..9cee76d1404 100644
--- a/src/HotChocolate/Core/test/Validation.Tests/ValuesOfCorrectTypeRuleTests.cs
+++ b/src/HotChocolate/Core/test/Validation.Tests/ValuesOfCorrectTypeRuleTests.cs
@@ -62,7 +62,7 @@ query queryWithListInput()
"The specified argument value does not" +
" match the argument type.",
t.Message);
- Assert.Equal("[Boolean!]", t.Extensions["locationType"]);
+ Assert.Equal("[Boolean!]", t.Extensions!["locationType"]);
Assert.Equal("booleanListArg", t.Extensions["argument"]);
});
}
@@ -81,7 +81,7 @@ query queryWithListInput()
"The specified argument value does not" +
" match the argument type.",
t.Message);
- Assert.Equal("[Boolean!]", t.Extensions["locationType"]);
+ Assert.Equal("[Boolean!]", t.Extensions!["locationType"]);
Assert.Equal("booleanListArg", t.Extensions["argument"]);
});
}
@@ -668,6 +668,17 @@ public void BadWrongCasingEnumIntoEnum()
");
}
+ [Fact(Skip = "This really should be caught! " +
+ "=> Spec issue http://spec.graphql.org/draft/#sel-JALTHHDHFFCAACEQl_M")]
+ public void BadNullToString()
+ {
+ ExpectErrors(@"
+ query InvalidItem {
+ nonNull(a: null)
+ }
+ ");
+ }
+
[Fact]
public void GoodListValue()
{
diff --git a/src/HotChocolate/Core/test/Validation.Tests/__snapshots__/ValuesOfCorrectTypeRuleTests.BadNullToString.snap b/src/HotChocolate/Core/test/Validation.Tests/__snapshots__/ValuesOfCorrectTypeRuleTests.BadNullToString.snap
new file mode 100644
index 00000000000..e3b9502de6d
--- /dev/null
+++ b/src/HotChocolate/Core/test/Validation.Tests/__snapshots__/ValuesOfCorrectTypeRuleTests.BadNullToString.snap
@@ -0,0 +1,24 @@
+[
+ {
+ "Message": "The specified argument value does not match the argument type.",
+ "Code": null,
+ "Path": {
+ "Parent": null,
+ "Depth": 0,
+ "Name": "nonNull"
+ },
+ "Locations": [
+ {
+ "Line": 3,
+ "Column": 32
+ }
+ ],
+ "Extensions": {
+ "argument": "a",
+ "argumentValue": "null",
+ "locationType": "String!",
+ "specifiedBy": "http://spec.graphql.org/June2018/#sec-Values-of-Correct-Type"
+ },
+ "Exception": null
+ }
+]
diff --git a/src/HotChocolate/Stitching/test/Stitching.Tests/HotChocolate.Stitching.Tests.csproj b/src/HotChocolate/Stitching/test/Stitching.Tests/HotChocolate.Stitching.Tests.csproj
index cbe7f13b171..55a8be3407b 100644
--- a/src/HotChocolate/Stitching/test/Stitching.Tests/HotChocolate.Stitching.Tests.csproj
+++ b/src/HotChocolate/Stitching/test/Stitching.Tests/HotChocolate.Stitching.Tests.csproj
@@ -7,6 +7,7 @@
+
diff --git a/src/HotChocolate/Stitching/test/Stitching.Tests/Integration/BaseTests.cs b/src/HotChocolate/Stitching/test/Stitching.Tests/Integration/BaseTests.cs
index fababe77a97..275f6b03f25 100644
--- a/src/HotChocolate/Stitching/test/Stitching.Tests/Integration/BaseTests.cs
+++ b/src/HotChocolate/Stitching/test/Stitching.Tests/Integration/BaseTests.cs
@@ -9,6 +9,7 @@
using HotChocolate.Resolvers;
using HotChocolate.Types;
using HotChocolate.Language;
+using HotChocolate.Types.Descriptors.Definitions;
namespace HotChocolate.Stitching.Integration
{
@@ -521,7 +522,7 @@ public async Task AutoMerge_Execute_RenameScalar()
.ModifyRequestOptions(o => o.IncludeExceptionDetails = true)
.BuildRequestExecutorAsync();
- var variables = new Dictionary
+ var variables = new Dictionary
{
{ "v", new FloatValueNode(1.2f) }
};
@@ -581,9 +582,9 @@ public async Task AutoMerge_Execute_IntField()
.AddRemoteSchema(Context.CustomerSchema)
.AddTypeExtensionsFromString(
@"extend type Customer {
- int: Int!
+ int: Int!
@delegate(
- schema: ""contract"",
+ schema: ""contract"",
path: ""int(i:$fields:someInt)"")
}")
.ModifyRequestOptions(o => o.IncludeExceptionDetails = true)
@@ -616,9 +617,9 @@ public async Task AutoMerge_Execute_GuidField()
.AddRemoteSchema(Context.CustomerSchema)
.AddTypeExtensionsFromString(
@"extend type Customer {
- guid: Uuid!
+ guid: Uuid!
@delegate(
- schema: ""contract"",
+ schema: ""contract"",
path: ""guid(guid:$fields:someGuid)"")
}")
.ModifyRequestOptions(o => o.IncludeExceptionDetails = true)
diff --git a/src/HotChocolate/Stitching/test/Stitching.Tests/Integration/RewriteTypesTests.cs b/src/HotChocolate/Stitching/test/Stitching.Tests/Integration/RewriteTypesTests.cs
new file mode 100644
index 00000000000..1b6568f4e73
--- /dev/null
+++ b/src/HotChocolate/Stitching/test/Stitching.Tests/Integration/RewriteTypesTests.cs
@@ -0,0 +1,132 @@
+using System;
+using System.Linq;
+using System.Net.Http;
+using System.Threading.Tasks;
+using ChilliCream.Testing;
+using HotChocolate.Execution;
+using HotChocolate.Language;
+using HotChocolate.Types;
+using HotChocolate.Utilities;
+using Microsoft.Extensions.DependencyInjection;
+using Xunit;
+
+namespace HotChocolate.Stitching.Integration
+{
+ public class RewriteTypesTests : IClassFixture
+ {
+ public RewriteTypesTests(StitchingTestContext context)
+ {
+ Context = context;
+ }
+
+ protected StitchingTestContext Context { get; }
+
+ [Fact]
+ public async Task AutoMerge_Schema()
+ {
+ // arrange
+ IHttpClientFactory httpClientFactory =
+ Context.CreateDefaultRemoteSchemas();
+
+ // act
+ IServiceProvider services =
+ new ServiceCollection()
+ .AddSingleton(httpClientFactory)
+ .AddGraphQL()
+ .AddRemoteSchemaFromString(
+ "AdvisorClient",
+ FileResource.Open("AdvisorClient.graphql"))
+ .AddRemoteSchemaFromString(
+ "ContractClient",
+ FileResource.Open("ContractClient.graphql"))
+ .AddRemoteSchemaFromString(
+ "DocumentClient",
+ FileResource.Open("DocumentClient.graphql"))
+ .AddType(new IntType("PaginationAmount"))
+ .AddType(new IntType())
+ .AddMergedDocumentRewriter(d =>
+ {
+ var rewriter = new DocumentRewriter();
+ return (DocumentNode)rewriter.Rewrite(d, null);
+ })
+ .RewriteType("ContractClient", "Int", "PaginationAmount")
+ .AddGraphQL("AdvisorClient")
+ .AddType(new IntType("PaginationAmount"))
+ .AddType(new IntType())
+ .AddGraphQL("ContractClient")
+ .AddType(new IntType("PaginationAmount"))
+ .AddType(new IntType())
+ .AddGraphQL("DocumentClient")
+ .AddType(new IntType("PaginationAmount"))
+ .AddType(new IntType())
+ .Services
+ .BuildServiceProvider();
+
+ // assert
+ IRequestExecutor contractExecutor =
+ await services.GetRequestExecutorAsync("ContractClient");
+
+ ObjectType type = contractExecutor.Schema.GetType("ZmaContract");
+
+ Assert.Equal(
+ "Int",
+ type.Fields["accountTransactions"].Arguments["first"].Type.NamedType().Name.Value);
+
+ IRequestExecutor executor =
+ await services.GetRequestExecutorAsync();
+
+ type = executor.Schema.GetType("ZmaContract");
+
+ Assert.Equal(
+ "PaginationAmount",
+ type.Fields["accountTransactions"].Arguments["first"].Type.NamedType().Name.Value);
+ }
+
+ private class DocumentRewriter : SchemaSyntaxRewriter