Skip to content

Commit

Permalink
Add more tests for federated stitching. (#2474)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Oct 25, 2020
1 parent 32bfa7f commit 0de8364
Show file tree
Hide file tree
Showing 44 changed files with 948 additions and 363 deletions.
Expand Up @@ -59,7 +59,7 @@ private async ValueTask InitializeAsync(CancellationToken cancellationToken)
{
_disposables.Add(provider.OnChange(OnChange));

IEnumerable<NamedRequestExecutorFactoryOptions> allOptions =
IEnumerable<INamedRequestExecutorFactoryOptions> allOptions =
await provider.GetOptionsAsync(cancellationToken)
.ConfigureAwait(false);

Expand Down
@@ -0,0 +1,16 @@
using Microsoft.Extensions.Options;

namespace HotChocolate.Execution.Configuration
{
/// <summary>
/// Represents something that configures the <see cref="RequestExecutorFactoryOptions"/>.
/// </summary>
public interface INamedRequestExecutorFactoryOptions
: IConfigureOptions<RequestExecutorFactoryOptions>
{
/// <summary>
/// The schema name to which this instance provides configurations to.
/// </summary>
NameString SchemaName { get; }
}
}
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace HotChocolate.Execution.Configuration
{
/// <summary>
/// Provides dynamic configurations.
/// </summary>
public interface IRequestExecutorOptionsProvider
{
/// <summary>
/// Gets named configuration options.
/// </summary>
/// <param name="cancellationToken">
/// The <see cref="CancellationToken"/>.
/// </param>
/// <returns>
/// Returns the configuration options of this provider.
/// </returns>
ValueTask<IEnumerable<INamedRequestExecutorFactoryOptions>> GetOptionsAsync(
CancellationToken cancellationToken);

/// <summary>
/// Registers a listener to be called whenever a named
/// <see cref="RequestExecutorFactoryOptions"/> changes.
/// </summary>
/// <param name="listener">
/// The action to be invoked when <see cref="RequestExecutorFactoryOptions"/> has changed.
/// </param>
/// <returns>
/// An <see cref="IDisposable"/> which should be disposed to stop listening for changes.
/// </returns>
IDisposable OnChange(Action<INamedRequestExecutorFactoryOptions> listener);
}
}
@@ -0,0 +1,45 @@
using System;

namespace HotChocolate.Execution.Configuration
{
public sealed class NamedRequestExecutorFactoryOptions
: INamedRequestExecutorFactoryOptions
{
private readonly Action<RequestExecutorFactoryOptions> _configure;

public NamedRequestExecutorFactoryOptions(
NameString schemaName,
Action<RequestExecutorFactoryOptions> configure)
{
SchemaName = schemaName.EnsureNotEmpty(nameof(schemaName));
_configure = configure ?? throw new ArgumentNullException(nameof(configure));
}

/*
public NamedRequestExecutorFactoryOptions(
NameString schemaName,
RequestExecutorFactoryOptions options)
{
SchemaName = schemaName.EnsureNotEmpty(nameof(schemaName));
_configure = o =>
{
options.Pipeline
}
}
*/

public NameString SchemaName { get; }

public void Configure(RequestExecutorFactoryOptions options)
{
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}

_configure(options);
}
}
}
@@ -1,10 +1,7 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using HotChocolate.Execution.Options;
using Microsoft.Extensions.Options;

namespace HotChocolate.Execution.Configuration
{
Expand Down Expand Up @@ -34,72 +31,4 @@ public class RequestExecutorFactoryOptions
public IList<OnRequestExecutorEvictedAction> OnRequestExecutorEvicted { get; } =
new List<OnRequestExecutorEvictedAction>();
}

/// <summary>
/// Provides dynamic configurations.
/// </summary>
public interface IRequestExecutorOptionsProvider
{
/// <summary>
/// Gets named configuration options.
/// </summary>
/// <param name="cancellationToken">
/// The <see cref="CancellationToken"/>.
/// </param>
/// <returns>
/// Returns the configuration options of this provider.
/// </returns>
ValueTask<IEnumerable<NamedRequestExecutorFactoryOptions>> GetOptionsAsync(
CancellationToken cancellationToken);

/// <summary>
/// Registers a listener to be called whenever a named
/// <see cref="RequestExecutorFactoryOptions"/> changes.
/// </summary>
/// <param name="listener">
/// The action to be invoked when <see cref="RequestExecutorFactoryOptions"/> has changed.
/// </param>
/// <returns>
/// An <see cref="IDisposable"/> which should be disposed to stop listening for changes.
/// </returns>
IDisposable OnChange(Action<INamedRequestExecutorFactoryOptions> listener);
}

/// <summary>
/// Represents something that configures the <see cref="RequestExecutorFactoryOptions"/>.
/// </summary>
public interface INamedRequestExecutorFactoryOptions
: IConfigureOptions<RequestExecutorFactoryOptions>
{
/// <summary>
/// The schema name to which this instance provides configurations to.
/// </summary>
NameString SchemaName { get; }
}

public sealed class NamedRequestExecutorFactoryOptions
: INamedRequestExecutorFactoryOptions
{
private readonly Action<RequestExecutorFactoryOptions> _configure;

public NamedRequestExecutorFactoryOptions(
NameString schemaName,
Action<RequestExecutorFactoryOptions> configure)
{
SchemaName = schemaName.EnsureNotEmpty(nameof(schemaName));
_configure = configure ?? throw new ArgumentNullException(nameof(configure));
}

public NameString SchemaName { get; }

public void Configure(RequestExecutorFactoryOptions options)
{
if (options is null)
{
throw new ArgumentNullException(nameof(options));
}

_configure(options);
}
}
}
Expand Up @@ -52,7 +52,7 @@ public interface ITypeCompletionContext
/// </returns>
/// <exception cref="SchemaException">
/// The type could not be resolved for the given <paramref name="typeRef" />.
/// </exception cref="SchemaException">
/// </exception>
T GetType<T>(ITypeReference typeRef) where T : IType;

IEnumerable<T> GetTypes<T>() where T : IType;
Expand Down
Expand Up @@ -52,96 +52,95 @@ public SchemaSyntaxVisitor(IBindingLookup bindingLookup)

public string Description { get; private set; }

public IReadOnlyCollection<DirectiveNode> Directives
{ get; private set; }
public IReadOnlyCollection<DirectiveNode> Directives { get; private set; }

public IReadOnlyList<ITypeReference> Types => _types;

protected override void VisitObjectTypeDefinition(
ObjectTypeDefinitionNode node,
object context)
{
_types.Add(SchemaTypeReference.Create(
_types.Add(TypeReference.Create(
_objectTypeFactory.Create(_bindingLookup, node)));
}

protected override void VisitObjectTypeExtension(
ObjectTypeExtensionNode node,
object context)
{
_types.Add(SchemaTypeReference.Create(
_types.Add(TypeReference.Create(
_objectTypeExtensionFactory.Create(_bindingLookup, node)));
}

protected override void VisitInterfaceTypeDefinition(
InterfaceTypeDefinitionNode node,
object context)
{
_types.Add(SchemaTypeReference.Create(
_types.Add(TypeReference.Create(
_interfaceTypeFactory.Create(_bindingLookup, node)));
}

protected override void VisitInterfaceTypeExtension(
InterfaceTypeExtensionNode node,
object context)
{
_types.Add(SchemaTypeReference.Create(
_types.Add(TypeReference.Create(
_interfaceTypeExtensionFactory.Create(_bindingLookup, node)));
}

protected override void VisitUnionTypeDefinition(
UnionTypeDefinitionNode node,
object context)
{
_types.Add(SchemaTypeReference.Create(
_types.Add(TypeReference.Create(
_unionTypeFactory.Create(_bindingLookup, node)));
}

protected override void VisitUnionTypeExtension(
UnionTypeExtensionNode node,
object context)
{
_types.Add(SchemaTypeReference.Create(
_types.Add(TypeReference.Create(
_unionTypeExtensionFactory.Create(_bindingLookup, node)));
}

protected override void VisitInputObjectTypeDefinition(
InputObjectTypeDefinitionNode node,
object context)
{
_types.Add(SchemaTypeReference.Create(
_types.Add(TypeReference.Create(
_inputObjectTypeFactory.Create(_bindingLookup, node)));
}

protected override void VisitInputObjectTypeExtension(
InputObjectTypeExtensionNode node,
object context)
{
_types.Add(SchemaTypeReference.Create(
_types.Add(TypeReference.Create(
_inputObjectTypeExtensionFactory.Create(_bindingLookup, node)));
}

protected override void VisitEnumTypeDefinition(
EnumTypeDefinitionNode node,
object context)
{
_types.Add(SchemaTypeReference.Create(
_types.Add(TypeReference.Create(
_enumTypeFactory.Create(_bindingLookup, node)));
}

protected override void VisitEnumTypeExtension(
EnumTypeExtensionNode node,
object context)
{
_types.Add(SchemaTypeReference.Create(
_types.Add(TypeReference.Create(
_enumTypeExtensionFactory.Create(_bindingLookup, node)));
}

protected override void VisitDirectiveDefinition(
DirectiveDefinitionNode node,
object context)
{
_types.Add(SchemaTypeReference.Create(
_types.Add(TypeReference.Create(
_directiveTypeFactory.Create(_bindingLookup, node)));
}

Expand Down
2 changes: 1 addition & 1 deletion src/HotChocolate/Core/src/Types/Types/ObjectField.cs
Expand Up @@ -122,7 +122,7 @@ internal ObjectField(ObjectFieldDefinition definition, bool sortArgumentsByName
ObjectFieldDefinition definition)
{
var isIntrospectionField = IsIntrospectionField
|| DeclaringType.IsIntrospectionType();
|| DeclaringType.IsIntrospectionType();

Resolver = definition.Resolver!;

Expand Down
Expand Up @@ -506,12 +506,31 @@ public void ObjectTypeExtension_RepeatableDirectiveOnArgument()

// assert
ObjectType type = schema.GetType<ObjectType>("Foo");
int count = type.Fields["name"].Arguments["a"]
var count = type.Fields["name"].Arguments["a"]
.Directives["dummy_rep"]
.Count();
Assert.Equal(2, count);
}

[Fact]
public void ObjectTypeExtension_SetDirectiveOnArgument_Sdl_First()
{
// arrange
// act
ISchema schema = SchemaBuilder.New()
.AddQueryType<FooType>()
.AddDocumentFromString(
@"extend type Foo {
name(a: String @dummy): String
}")
.AddDirectiveType<DummyDirective>()
.Create();

// assert
ObjectType type = schema.GetType<ObjectType>("Foo");
Assert.True(type.Fields["name"].Arguments["a"].Directives.Contains("dummy"));
}

public class FooType
: ObjectType<Foo>
{
Expand Down
Expand Up @@ -3,7 +3,7 @@
using Microsoft.Extensions.DependencyInjection;
using StackExchange.Redis;
using HotChocolate.Execution;
using HotChocolate.PersistedQueries.FileSystem;
using HotChocolate.PersistedQueries.Redis;

namespace HotChocolate
{
Expand Down
Expand Up @@ -5,7 +5,7 @@
using HotChocolate.Language;
using StackExchange.Redis;

namespace HotChocolate.PersistedQueries.FileSystem
namespace HotChocolate.PersistedQueries.Redis
{
/// <summary>
/// An implementation of <see cref="IReadStoredQueries"/>
Expand Down Expand Up @@ -45,13 +45,7 @@ public RedisQueryStorage(IDatabase database)
string queryId)
{
var buffer = (byte[]?)await _database.StringGetAsync(queryId).ConfigureAwait(false);

if (buffer is null)
{
return null;
}

return new QueryDocument(Utf8GraphQLParser.Parse(buffer));
return buffer is null ? null : new QueryDocument(Utf8GraphQLParser.Parse(buffer));
}

/// <inheritdoc />
Expand Down
Expand Up @@ -3,7 +3,6 @@
using Microsoft.Extensions.DependencyInjection;
using HotChocolate.Types;
using HotChocolate.Execution;
using HotChocolate.PersistedQueries.FileSystem;
using Snapshooter.Xunit;
using Squadron;
using StackExchange.Redis;
Expand Down

0 comments on commit 0de8364

Please sign in to comment.