Skip to content

Commit

Permalink
Added initial end to end integration for the new gateway. (#5284)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Aug 11, 2022
1 parent 1f88841 commit f284264
Show file tree
Hide file tree
Showing 82 changed files with 5,020 additions and 65 deletions.
3 changes: 2 additions & 1 deletion src/CookieCrumble/test/CookieCrumble.Tests/SnapshotTests.cs
Expand Up @@ -88,7 +88,8 @@ public void SnapshotBuilder_Segment_Custom_Serializer_For_Segment()
{
var snapshot = new Snapshot();
snapshot.Add(new MyClass());
snapshot.Add(new MyClass { Foo = "Bar" }, "Bar:", new CustomSerializer());
snapshot.Add(new MyClass { Foo = "Baz" }, "Bar:", new CustomSerializer());
snapshot.Add(new MyClass { Foo = "Baz" });
snapshot.Add(new MyClass { Foo = "Baz" });
snapshot.Match();
}
Expand Down
Expand Up @@ -14,6 +14,8 @@
<ItemGroup>
<InternalsVisibleTo Include="HotChocolate.Types.Mutations" />
<InternalsVisibleTo Include="HotChocolate.AspNetCore.Tests" />
<InternalsVisibleTo Include="HotChocolate.Fusion" />
<InternalsVisibleTo Include="HotChocolate.Fusion.Tests" />
<InternalsVisibleTo Include="StrawberryShake.CodeGeneration" />
</ItemGroup>

Expand Down
Expand Up @@ -37,9 +37,29 @@ public sealed class ListResult : ResultData, IReadOnlyList<object?>
internal void AddUnsafe(object? item)
=> _buffer[_count++] = item;

internal void AddUnsafe(ResultData? item)
{
if (item is not null)
{
item.Parent = this;
}

_buffer[_count++] = item;
}

internal void SetUnsafe(int index, object? item)
=> _buffer[index] = item;

internal void SetUnsafe(int index, ResultData? item)
{
if (item is not null)
{
item.Parent = this;
}

_buffer[index] = item;
}

/// <summary>
/// Ensures that the result object has enough capacity on the buffer
/// to store the expected fields.
Expand Down
Expand Up @@ -56,6 +56,32 @@ public sealed class ObjectResult
internal void SetValueUnsafe(int index, string name, object? value, bool isNullable = true)
=> _buffer[index].Set(name, value, isNullable);

/// <summary>
/// Sets a field value in the buffer.
/// Note: Set will not validate if the buffer has enough space.
/// </summary>
/// <param name="index">
/// The index in the buffer on which the value shall be stored.
/// </param>
/// <param name="name">
/// The name of the field.
/// </param>
/// <param name="value">
/// The field value.
/// </param>
/// <param name="isNullable">
/// Specifies if the value is allowed to be null.
/// </param>
internal void SetValueUnsafe(int index, string name, ResultData? value, bool isNullable = true)
{
if (value is not null)
{
value.Parent = this;
}

_buffer[index].Set(name, value, isNullable);
}

/// <summary>
/// Removes a field value from the buffer.
/// Note: Remove will not validate if the buffer has enough space.
Expand Down Expand Up @@ -137,7 +163,7 @@ internal void Reset()
{
Unsafe.Add(ref searchSpace, i).Reset();
}

_capacity = 0;
}

Expand Down
14 changes: 13 additions & 1 deletion src/HotChocolate/Core/src/Execution/Processing/Selection.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using HotChocolate.Execution.Properties;
using HotChocolate.Language;
Expand Down Expand Up @@ -96,6 +97,9 @@ protected Selection(Selection selection)
/// <inheritdoc />
public IObjectType DeclaringType { get; }

/// <inheritdoc />
public ISelectionSet DeclaringSelectionSet { get; private set; } = default!;

/// <inheritdoc />
public IObjectField Field { get; }

Expand Down Expand Up @@ -184,6 +188,9 @@ public bool IsIncluded(long includeFlags, bool allowInternals = false)
return false;
}

public override string ToString()
=> SyntaxNode.ToString();

internal void AddSelection(FieldNode selectionSyntax, long includeCondition = 0)
{
if ((_flags & Flags.Sealed) == Flags.Sealed)
Expand Down Expand Up @@ -303,12 +310,17 @@ internal void MarkAsStream(long ifCondition)
_flags |= Flags.Stream;
}

internal void Seal()
internal void Seal(ISelectionSet declaringSelectionSet)
{
if ((_flags & Flags.Sealed) != Flags.Sealed)
{
DeclaringSelectionSet = declaringSelectionSet;
_flags |= Flags.Sealed;
}

Debug.Assert(
ReferenceEquals(declaringSelectionSet, DeclaringSelectionSet),
"Selections can only belong to a single selectionSet.");
}

private SelectionExecutionStrategy InferStrategy(
Expand Down
Expand Up @@ -72,7 +72,7 @@ internal void Seal()
{
for (var i = 0; i < _selections.Length; i++)
{
_selections[i].Seal();
_selections[i].Seal(this);
}

_flags |= Flags.Sealed;
Expand All @@ -83,7 +83,7 @@ internal void Seal()
/// Returns a reference to the 0th element of the underlying selections array.
/// If the selections array is empty, returns a reference to the location where the 0th element
/// would have been stored. Such a reference may or may not be null.
/// It can be used for pinning but must never be dereferenced.
/// It can be used for pinning but must never be de-referenced.
/// This is only meant for use by the execution engine.
/// </summary>
internal ref Selection GetSelectionsReference()
Expand Down
Expand Up @@ -67,11 +67,7 @@ public async ValueTask InvokeAsync(IMiddlewareContext context)
throw;
}

context.SetScopedState(ErrorContextDataKeys.Errors,
new[]
{
error
});
context.SetScopedState(ErrorContextDataKeys.Errors, new[] { error });
context.Result = ErrorObject;
}
}
Expand Down
Expand Up @@ -72,6 +72,6 @@ public async ValueTask InvokeAsync(IMiddlewareContext context)
}
}

internal static object Null { get; } = new object();
internal static object Null { get; } = new();
}

Expand Up @@ -3,20 +3,19 @@
namespace HotChocolate.Types.Pagination;

/// <summary>
/// Represents an offset paging provider, which can be implemented to
/// create optimized pagination for data sources.
///
/// The paging provider will be used by the configuration to choose
/// Represents an offset paging provider, which can be implemented to
/// create optimized pagination for data sources.
///
/// The paging provider will be used by the configuration to choose
/// the right paging handler for executing the field.
/// </summary>
public abstract class OffsetPagingProvider
: IPagingProvider
public abstract class OffsetPagingProvider : IPagingProvider
{
/// <summary>
/// Specifies if this paging provider can handle the specified <see cref="source"/>.
/// Specifies if this paging provider can handle the specified <paramref name="source"/>.
/// </summary>
/// <param name="source">
/// The source type represents the result of the field resolver and could be a collection,
/// The source type represents the result of the field resolver and could be a collection,
/// a query builder or some other object representing the data set.
/// </param>
public abstract bool CanHandle(IExtendedType source);
Expand All @@ -30,7 +29,7 @@ public abstract class OffsetPagingProvider
/// Creates the paging handler for offset pagination.
/// </summary>
/// <param name="source">
/// The source type represents the result of the field resolver and could be a collection,
/// The source type represents the result of the field resolver and could be a collection,
/// a query builder or some other object representing the data set.
/// </param>
/// <param name="options">
Expand Down
Expand Up @@ -43,10 +43,15 @@ public interface ISelection : IOptionalSelection
bool IsList { get; }

/// <summary>
/// The type that declares the field that is selected by this selection.
/// Gets the type that declares the field that is selected by this selection.
/// </summary>
IObjectType DeclaringType { get; }

/// <summary>
/// Gets the selectionSet that declares this selection.
/// </summary>
ISelectionSet DeclaringSelectionSet { get; }

/// <summary>
/// Gets the field selection syntax node.
/// </summary>
Expand Down
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using HotChocolate.Language;
using HotChocolate.Properties;
Expand All @@ -9,7 +10,11 @@ public static partial class SchemaBuilderExtensions
{
public static ISchemaBuilder AddDocumentFromString(
this ISchemaBuilder builder,
#if NET7_0_OR_GREATER
[StringSyntax("graphql")] string schema)
#else
string schema)
#endif
{
if (builder is null)
{
Expand Down
Expand Up @@ -389,7 +389,7 @@ public async Task Create_ShortIn_Expression()

var res2 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root(where: { barShort: { in: [ null, 14 ]}}){ barShort}}")
.SetQuery("{ root(where: { barShort: { in: [ 13, 14 ]}}){ barShort}}")
.Create());

var res3 = await tester.ExecuteAsync(
Expand Down Expand Up @@ -419,7 +419,7 @@ public async Task Create_ShortNotIn_Expression()

var res2 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root(where: { barShort: { nin: [ null, 14 ]}}){ barShort}}")
.SetQuery("{ root(where: { barShort: { nin: [ 13, 14 ]}}){ barShort}}")
.Create());

var res3 = await tester.ExecuteAsync(
Expand Down
Expand Up @@ -557,7 +557,8 @@ public async Task Create_ShortNotIn_Expression()
var res2 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery(
"{ root(where: { barShort: { nin: [ null, \"Rm9vCnMxNA==\"]}}){ barShort}}")
"{ root(where: { barShort: { nin: " +
"[ \"Rm9vCnMxMg==\", \"Rm9vCnMxNA==\"]}}){ barShort}}")
.Create());

var res3 = await tester.ExecuteAsync(
Expand Down
Expand Up @@ -200,7 +200,7 @@ public async Task Create_ObjectShortIn_Expression()
var res2 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery(
"{ root(where: { foo: { barShort: { in: [ null, 14 ]}}}) " +
"{ root(where: { foo: { barShort: { in: [ 13, 14 ]}}}) " +
"{ foo{ barShort}}}")
.Create());

Expand Down
Expand Up @@ -397,7 +397,7 @@ public async Task Create_ShortIn_Expression()

var res2 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root(where: { barShort: { in: [ null, 14 ]}}){ barShort}}")
.SetQuery("{ root(where: { barShort: { in: [ 13, 14 ]}}){ barShort}}")
.Create());

var res3 = await tester.ExecuteAsync(
Expand Down Expand Up @@ -428,7 +428,7 @@ public async Task Create_ShortNotIn_Expression()

var res2 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery("{ root(where: { barShort: { nin: [ null, 14 ]}}){ barShort}}")
.SetQuery("{ root(where: { barShort: { nin: [ 13, 14 ]}}){ barShort}}")
.Create());

var res3 = await tester.ExecuteAsync(
Expand Down
Expand Up @@ -163,7 +163,7 @@ public async Task Create_ObjectShortIn_Expression()
var res2 = await tester.ExecuteAsync(
QueryRequestBuilder.New()
.SetQuery(
"{ root(where: { foo: { barShort: { in: [ null, 14 ]}}}) " +
"{ root(where: { foo: { barShort: { in: [ 13, 14 ]}}}) " +
"{ foo{ barShort}}}")
.Create());

Expand Down
@@ -1,8 +1,8 @@
using System;
using System.Linq;
using CookieCrumble;
using HotChocolate.Data.Filters;
using HotChocolate.Types;
using CookieCrumble;

namespace HotChocolate.Data.Tests;

Expand Down Expand Up @@ -41,13 +41,13 @@ public void Convention_DefaultScope_Extensions()
public void ObjectField_UseFiltering()
{
// arrange
// act
var builder = SchemaBuilder.New()
.AddFiltering()
.AddQueryType<Query>(
c =>
c.Field(x => x.GetFoos()).UseFiltering());

// act
var schema = builder.Create();

// assert
Expand Down
16 changes: 16 additions & 0 deletions src/HotChocolate/Fusion/src/Core/Execution/Argument.cs
@@ -0,0 +1,16 @@
using HotChocolate.Language;

namespace HotChocolate.Fusion.Execution;

internal readonly struct Argument
{
public Argument(string name, IValueNode value)
{
Name = name;
Value = value;
}

public string Name { get; }

public IValueNode Value { get; }
}

0 comments on commit f284264

Please sign in to comment.