Skip to content

Commit

Permalink
Added projections support to version 11 (#2419)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Staib <michael@chillicream.com>
  • Loading branch information
PascalSenn and michaelstaib committed Oct 18, 2020
1 parent 762b09e commit 5360b70
Show file tree
Hide file tree
Showing 216 changed files with 7,968 additions and 159 deletions.
Expand Up @@ -78,8 +78,10 @@ private class CompilerContext

public bool IsInternalSelection { get; }

public IDictionary<ISelectionNode, SelectionIncludeCondition> IncludeConditionLookup
{ get; }
public IDictionary<ISelectionNode, SelectionIncludeCondition> IncludeConditionLookup
{
get;
}

public IImmutableList<ISelectionOptimizer> Optimizers { get; }

Expand All @@ -93,6 +95,7 @@ public void RegisterFragment(IFragment fragment)
{
_fragments = new List<IFragment>();
}

_fragments.Add(fragment);
}

Expand All @@ -105,7 +108,7 @@ public void TryBranch(ObjectType type, ISelection selection)
{
SelectionSetNode selectionSet = selection.SelectionSet!;

if(!_processed.Add((selectionSet, type.Name)))
if (!_processed.Add((selectionSet, type.Name)))
{
return;
}
Expand All @@ -118,8 +121,7 @@ public void TryBranch(ObjectType type, ISelection selection)
_variantsLookup[selectionSet] = selectionVariants;
}

var context = new CompilerContext
(
var context = new CompilerContext(
type,
Path.Push(selection.Field),
selectionSet,
Expand All @@ -145,8 +147,7 @@ public CompilerContext Branch(FragmentInfo fragment)
_variantsLookup[fragment.SelectionSet] = selectionVariants;
}

var context = new CompilerContext
(
var context = new CompilerContext(
Type,
Path,
fragment.SelectionSet,
Expand All @@ -172,8 +173,7 @@ public CompilerContext Branch(FragmentInfo fragment)
var rootSelections = new SelectionVariants(selectionSet);
selectionVariantsLookup[selectionSet] = rootSelections;

var context = new CompilerContext
(
var context = new CompilerContext(
backlog,
type,
selectionSet,
Expand Down
25 changes: 19 additions & 6 deletions src/HotChocolate/Core/src/Execution/Processing/Selection.cs
Expand Up @@ -9,7 +9,7 @@

namespace HotChocolate.Execution.Processing
{
public sealed class Selection : ISelection
public class Selection : ISelection
{
private static readonly ArgumentMap _emptyArguments =
new ArgumentMap(new Dictionary<NameString, ArgumentValue>());
Expand Down Expand Up @@ -56,6 +56,21 @@ public sealed class Selection : ISelection
}
}

public Selection(Selection selection)
{
_includeConditions = selection._includeConditions;
_selections = selection._selections;
_isReadOnly = selection._isReadOnly;
DeclaringType = selection.DeclaringType;
Field = selection.Field;
SyntaxNode = selection.SyntaxNode;
SyntaxNodes = selection.SyntaxNodes;
ResponseName = selection.ResponseName;
ResolverPipeline = selection.ResolverPipeline;
Arguments = selection.Arguments;
InclusionKind = selection.InclusionKind;
}

/// <inheritdoc />
public IObjectType DeclaringType { get; }

Expand Down Expand Up @@ -189,8 +204,7 @@ internal void MakeReadOnly()
return first;
}

return new FieldNode
(
return new FieldNode(
first.Location,
first.Name,
first.Alias,
Expand Down Expand Up @@ -219,8 +233,7 @@ internal void MakeReadOnly()
}
}

return new SelectionSetNode
(
return new SelectionSetNode(
selections[0].SelectionSet!.Location,
children
);
Expand Down Expand Up @@ -269,7 +282,7 @@ internal void MakeReadOnly()
private void ModifyCondition(bool hasConditions) =>
InclusionKind =
(InclusionKind == SelectionInclusionKind.Internal
|| InclusionKind == SelectionInclusionKind.InternalConditional)
|| InclusionKind == SelectionInclusionKind.InternalConditional)
? (hasConditions
? SelectionInclusionKind.InternalConditional
: SelectionInclusionKind.Internal)
Expand Down
1 change: 0 additions & 1 deletion src/HotChocolate/Core/src/Execution/ThrowHelper.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using HotChocolate.Execution.Properties;
using HotChocolate.Language;
using static HotChocolate.Execution.Properties.Resources;

Expand Down
Expand Up @@ -86,5 +86,7 @@ IObjectFieldDescriptor Directive<T>()
IObjectFieldDescriptor Directive(
NameString name,
params ArgumentNode[] arguments);

IObjectFieldDescriptor ConfigureContextData(Action<ExtensionData> configure);
}
}
Expand Up @@ -48,7 +48,7 @@ public interface IObjectTypeDescriptor<T>
/// </param>
IObjectTypeDescriptor<T> BindFields(BindingBehavior behavior);

/// <summary>
/// <summary>
/// Defines that all fields have to be specified explicitly.
/// </summary>
IObjectTypeDescriptor<T> BindFieldsExplicitly();
Expand Down
Expand Up @@ -46,6 +46,11 @@ public T CreateDefinition()
return Definition;
}

public void ConfigureContextData(Action<ExtensionData> configure)
{
configure(Definition.ContextData);
}

protected virtual void OnCreateDefinition(T definition)
{
}
Expand Down Expand Up @@ -88,7 +93,7 @@ private void OnBeforeCreate(Action<IDescriptorContext, T> configure)
OnBeforeNaming(configure);

private INamedDependencyDescriptor OnBeforeNaming(
Action<ITypeCompletionContext, T> configure)
Action<ITypeCompletionContext, T> configure)
{
if (configure is null)
{
Expand Down
Expand Up @@ -46,22 +46,25 @@ public class ObjectFieldDescriptor
Definition.Member = member ??
throw new ArgumentNullException(nameof(member));
Definition.Name = context.Naming.GetMemberName(
member, MemberKind.ObjectField);
member,
MemberKind.ObjectField);
Definition.Description = context.Naming.GetMemberDescription(
member, MemberKind.ObjectField);
member,
MemberKind.ObjectField);
Definition.Type = context.TypeInspector.GetOutputReturnTypeRef(member);
Definition.SourceType = sourceType;
Definition.ResolverType = resolverType == sourceType ? null : resolverType;

if (context.Naming.IsDeprecated(member, out var reason))
{
Deprecated(reason);
}

if (member is MethodInfo m)
{
Parameters = m.GetParameters().ToDictionary(
t => new NameString(t.Name));
Parameters = m
.GetParameters()
.ToDictionary(t => new NameString(t.Name));
Definition.ResultType = m.ReturnType;
}
else if (member is PropertyInfo p)
Expand All @@ -87,9 +90,11 @@ public class ObjectFieldDescriptor
if (member is { })
{
Definition.Name = context.Naming.GetMemberName(
member, MemberKind.ObjectField);
member,
MemberKind.ObjectField);
Definition.Description = context.Naming.GetMemberDescription(
member, MemberKind.ObjectField);
member,
MemberKind.ObjectField);
Definition.Type = context.TypeInspector.GetOutputReturnTypeRef(member);

if (context.Naming.IsDeprecated(member, out string? reason))
Expand Down Expand Up @@ -127,7 +132,6 @@ public class ObjectFieldDescriptor
protected override void OnCreateDefinition(
ObjectFieldDefinition definition)
{

if (Definition.Member is { })
{
Context.TypeInspector.ApplyAttributes(
Expand Down Expand Up @@ -175,7 +179,7 @@ public new IObjectFieldDescriptor Name(NameString value)

[Obsolete("Use `Deprecated`.")]
public IObjectFieldDescriptor DeprecationReason(string? reason) =>
Deprecated(reason);
Deprecated(reason);

public new IObjectFieldDescriptor Deprecated(string? reason)
{
Expand Down Expand Up @@ -375,6 +379,13 @@ public new IObjectFieldDescriptor Directive<T>()
return this;
}

public new IObjectFieldDescriptor ConfigureContextData(
Action<ExtensionData> configure)
{
base.ConfigureContextData(configure);
return this;
}

public static ObjectFieldDescriptor New(
IDescriptorContext context,
NameString fieldName) =>
Expand Down
@@ -1,10 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using HotChocolate.Resolvers;
using static HotChocolate.Utilities.ThrowHelper;

#nullable enable

Expand All @@ -31,8 +27,9 @@ public async Task InvokeAsync(IMiddlewareContext context)

if (context.Result is not null)
{
context.Result =
await _pagingHandler.SliceAsync(context, context.Result).ConfigureAwait(false);
context.Result = await _pagingHandler
.SliceAsync(context, context.Result)
.ConfigureAwait(false);
}
}
}
Expand Down
61 changes: 48 additions & 13 deletions src/HotChocolate/Data/HotChocolate.Data.sln
Expand Up @@ -62,6 +62,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.Data.Filters.S
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.Data.Sorting.Tests", "test\Data.Sorting.Tests\HotChocolate.Data.Sorting.Tests.csproj", "{A7269FAC-8C91-46BA-B292-221E8DE32BD3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.Data.Projections.SqlServer.Tests", "test\Data.Projections.SqlServer.Tests\HotChocolate.Data.Projections.SqlServer.Tests.csproj", "{F9223FFE-BEA4-4C68-BF92-339FD9643084}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.Types.CursorPagination", "..\Core\src\Types.CursorPagination\HotChocolate.Types.CursorPagination.csproj", "{982D42FD-6E4D-41DC-8892-785BAA55294C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.Types.OffsetPagination", "..\Core\src\Types.OffsetPagination\HotChocolate.Types.OffsetPagination.csproj", "{1BC63911-799F-4189-801A-2B7C97FD2F23}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.Data.Sorting.InMemory.Tests", "test\Data.Sorting.InMemory.Tests\HotChocolate.Data.Sorting.InMemory.Tests.csproj", "{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolate.Data.Sorting.SqlLite.Tests", "test\Data.Sorting.SqlLite.Tests\HotChocolate.Data.Sorting.SqlLite.Tests.csproj", "{D445A9BB-D068-496A-B261-609799F95915}"
Expand Down Expand Up @@ -104,8 +110,11 @@ Global
{CCCD4A40-EA4F-4AF7-91A7-3D8DC14D186C} = {4EE990B2-C327-46DA-8FE8-F95AC228E47F}
{9B858A08-741A-4C11-A243-3739C4E57B15} = {4EE990B2-C327-46DA-8FE8-F95AC228E47F}
{A7269FAC-8C91-46BA-B292-221E8DE32BD3} = {4EE990B2-C327-46DA-8FE8-F95AC228E47F}
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA} = {4EE990B2-C327-46DA-8FE8-F95AC228E47F}
{F9223FFE-BEA4-4C68-BF92-339FD9643084} = {4EE990B2-C327-46DA-8FE8-F95AC228E47F}
{982D42FD-6E4D-41DC-8892-785BAA55294C} = {882EC02D-5E1D-41F5-AD9F-AA06E31D133A}
{1BC63911-799F-4189-801A-2B7C97FD2F23} = {882EC02D-5E1D-41F5-AD9F-AA06E31D133A}
{D445A9BB-D068-496A-B261-609799F95915} = {4EE990B2-C327-46DA-8FE8-F95AC228E47F}
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA} = {4EE990B2-C327-46DA-8FE8-F95AC228E47F}
{0E4E8E6F-A65C-42C0-BE9F-DFA002E59303} = {91887A91-7B1C-4287-A1E0-BD4E0DAF24C7}
{16FB6511-AE94-46C4-9652-2665C6816546} = {4EE990B2-C327-46DA-8FE8-F95AC228E47F}
EndGlobalSection
Expand Down Expand Up @@ -362,18 +371,42 @@ Global
{A7269FAC-8C91-46BA-B292-221E8DE32BD3}.Release|x64.Build.0 = Release|Any CPU
{A7269FAC-8C91-46BA-B292-221E8DE32BD3}.Release|x86.ActiveCfg = Release|Any CPU
{A7269FAC-8C91-46BA-B292-221E8DE32BD3}.Release|x86.Build.0 = Release|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Debug|x64.ActiveCfg = Debug|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Debug|x64.Build.0 = Debug|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Debug|x86.ActiveCfg = Debug|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Debug|x86.Build.0 = Debug|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Release|Any CPU.Build.0 = Release|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Release|x64.ActiveCfg = Release|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Release|x64.Build.0 = Release|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Release|x86.ActiveCfg = Release|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Release|x86.Build.0 = Release|Any CPU
{F9223FFE-BEA4-4C68-BF92-339FD9643084}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F9223FFE-BEA4-4C68-BF92-339FD9643084}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F9223FFE-BEA4-4C68-BF92-339FD9643084}.Debug|x64.ActiveCfg = Debug|Any CPU
{F9223FFE-BEA4-4C68-BF92-339FD9643084}.Debug|x64.Build.0 = Debug|Any CPU
{F9223FFE-BEA4-4C68-BF92-339FD9643084}.Debug|x86.ActiveCfg = Debug|Any CPU
{F9223FFE-BEA4-4C68-BF92-339FD9643084}.Debug|x86.Build.0 = Debug|Any CPU
{F9223FFE-BEA4-4C68-BF92-339FD9643084}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F9223FFE-BEA4-4C68-BF92-339FD9643084}.Release|Any CPU.Build.0 = Release|Any CPU
{F9223FFE-BEA4-4C68-BF92-339FD9643084}.Release|x64.ActiveCfg = Release|Any CPU
{F9223FFE-BEA4-4C68-BF92-339FD9643084}.Release|x64.Build.0 = Release|Any CPU
{F9223FFE-BEA4-4C68-BF92-339FD9643084}.Release|x86.ActiveCfg = Release|Any CPU
{F9223FFE-BEA4-4C68-BF92-339FD9643084}.Release|x86.Build.0 = Release|Any CPU
{982D42FD-6E4D-41DC-8892-785BAA55294C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{982D42FD-6E4D-41DC-8892-785BAA55294C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{982D42FD-6E4D-41DC-8892-785BAA55294C}.Debug|x64.ActiveCfg = Debug|Any CPU
{982D42FD-6E4D-41DC-8892-785BAA55294C}.Debug|x64.Build.0 = Debug|Any CPU
{982D42FD-6E4D-41DC-8892-785BAA55294C}.Debug|x86.ActiveCfg = Debug|Any CPU
{982D42FD-6E4D-41DC-8892-785BAA55294C}.Debug|x86.Build.0 = Debug|Any CPU
{982D42FD-6E4D-41DC-8892-785BAA55294C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{982D42FD-6E4D-41DC-8892-785BAA55294C}.Release|Any CPU.Build.0 = Release|Any CPU
{982D42FD-6E4D-41DC-8892-785BAA55294C}.Release|x64.ActiveCfg = Release|Any CPU
{982D42FD-6E4D-41DC-8892-785BAA55294C}.Release|x64.Build.0 = Release|Any CPU
{982D42FD-6E4D-41DC-8892-785BAA55294C}.Release|x86.ActiveCfg = Release|Any CPU
{982D42FD-6E4D-41DC-8892-785BAA55294C}.Release|x86.Build.0 = Release|Any CPU
{1BC63911-799F-4189-801A-2B7C97FD2F23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1BC63911-799F-4189-801A-2B7C97FD2F23}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1BC63911-799F-4189-801A-2B7C97FD2F23}.Debug|x64.ActiveCfg = Debug|Any CPU
{1BC63911-799F-4189-801A-2B7C97FD2F23}.Debug|x64.Build.0 = Debug|Any CPU
{1BC63911-799F-4189-801A-2B7C97FD2F23}.Debug|x86.ActiveCfg = Debug|Any CPU
{1BC63911-799F-4189-801A-2B7C97FD2F23}.Debug|x86.Build.0 = Debug|Any CPU
{1BC63911-799F-4189-801A-2B7C97FD2F23}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1BC63911-799F-4189-801A-2B7C97FD2F23}.Release|Any CPU.Build.0 = Release|Any CPU
{1BC63911-799F-4189-801A-2B7C97FD2F23}.Release|x64.ActiveCfg = Release|Any CPU
{1BC63911-799F-4189-801A-2B7C97FD2F23}.Release|x64.Build.0 = Release|Any CPU
{1BC63911-799F-4189-801A-2B7C97FD2F23}.Release|x86.ActiveCfg = Release|Any CPU
{1BC63911-799F-4189-801A-2B7C97FD2F23}.Release|x86.Build.0 = Release|Any CPU
{D445A9BB-D068-496A-B261-609799F95915}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D445A9BB-D068-496A-B261-609799F95915}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D445A9BB-D068-496A-B261-609799F95915}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand All @@ -386,6 +419,8 @@ Global
{D445A9BB-D068-496A-B261-609799F95915}.Release|x64.Build.0 = Release|Any CPU
{D445A9BB-D068-496A-B261-609799F95915}.Release|x86.ActiveCfg = Release|Any CPU
{D445A9BB-D068-496A-B261-609799F95915}.Release|x86.Build.0 = Release|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E5E0D684-4FF6-4124-8ADB-9E96A3FDA6FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E4E8E6F-A65C-42C0-BE9F-DFA002E59303}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E4E8E6F-A65C-42C0-BE9F-DFA002E59303}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E4E8E6F-A65C-42C0-BE9F-DFA002E59303}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down

0 comments on commit 5360b70

Please sign in to comment.