-
-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added DataLoader group refinements. (#7529)
(cherry picked from commit 3eac31b)
- Loading branch information
1 parent
b7c55f5
commit 0c9789a
Showing
7 changed files
with
330 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
...ests.GenerateSource_BatchDataLoader_With_Group_Only_On_Class_MatchesSnapshot.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# GenerateSource_BatchDataLoader_With_Group_Only_On_Class_MatchesSnapshot | ||
|
||
## GreenDonutDataLoader.735550c.g.cs | ||
|
||
```csharp | ||
// <auto-generated/> | ||
#nullable enable | ||
#pragma warning disable | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using GreenDonut; | ||
|
||
namespace TestNamespace | ||
{ | ||
public interface IEntityByIdDataLoader | ||
: global::GreenDonut.IDataLoader<int, global::TestNamespace.Entity> | ||
{ | ||
} | ||
|
||
public sealed class EntityByIdDataLoader | ||
: global::GreenDonut.DataLoaderBase<int, global::TestNamespace.Entity> | ||
, IEntityByIdDataLoader | ||
{ | ||
private readonly global::System.IServiceProvider _services; | ||
|
||
public EntityByIdDataLoader( | ||
global::System.IServiceProvider services, | ||
global::GreenDonut.IBatchScheduler batchScheduler, | ||
global::GreenDonut.DataLoaderOptions options) | ||
: base(batchScheduler, options) | ||
{ | ||
_services = services ?? | ||
throw new global::System.ArgumentNullException(nameof(services)); | ||
} | ||
|
||
protected override async global::System.Threading.Tasks.ValueTask FetchAsync( | ||
global::System.Collections.Generic.IReadOnlyList<int> keys, | ||
global::System.Memory<GreenDonut.Result<global::TestNamespace.Entity?>> results, | ||
global::GreenDonut.DataLoaderFetchContext<global::TestNamespace.Entity> context, | ||
global::System.Threading.CancellationToken ct) | ||
{ | ||
var temp = await TestNamespace.TestClass.GetEntityByIdAsync(keys, ct).ConfigureAwait(false); | ||
CopyResults(keys, results.Span, temp); | ||
} | ||
|
||
private void CopyResults( | ||
global::System.Collections.Generic.IReadOnlyList<int> keys, | ||
global::System.Span<GreenDonut.Result<global::TestNamespace.Entity?>> results, | ||
global::System.Collections.Generic.IReadOnlyDictionary<int, TestNamespace.Entity> resultMap) | ||
{ | ||
for (var i = 0; i < keys.Count; i++) | ||
{ | ||
var key = keys[i]; | ||
if (resultMap.TryGetValue(key, out var value)) | ||
{ | ||
results[i] = global::GreenDonut.Result<global::TestNamespace.Entity?>.Resolve(value); | ||
} | ||
else | ||
{ | ||
results[i] = global::GreenDonut.Result<global::TestNamespace.Entity?>.Resolve(default(global::TestNamespace.Entity)); | ||
} | ||
} | ||
} | ||
} | ||
public interface IGroup1 | ||
{ | ||
IEntityByIdDataLoader EntityById { get; } | ||
} | ||
|
||
public sealed class Group1 : IGroup1 | ||
{ | ||
private readonly IServiceProvider _services; | ||
private IEntityByIdDataLoader? _entityById; | ||
|
||
public Group1(IServiceProvider services) | ||
{ | ||
_services = services | ||
?? throw new ArgumentNullException(nameof(services)); | ||
} | ||
public IEntityByIdDataLoader EntityById | ||
{ | ||
get | ||
{ | ||
if (_entityById is null) | ||
{ | ||
_entityById = _services.GetRequiredService<IEntityByIdDataLoader>(); | ||
} | ||
|
||
return _entityById!; | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
``` | ||
|
||
## HotChocolateTypeModule.735550c.g.cs | ||
|
||
```csharp | ||
// <auto-generated/> | ||
#nullable enable | ||
#pragma warning disable | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
using HotChocolate; | ||
using HotChocolate.Types; | ||
using HotChocolate.Execution.Configuration; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public static partial class TestsTypesRequestExecutorBuilderExtensions | ||
{ | ||
public static IRequestExecutorBuilder AddTestsTypes(this IRequestExecutorBuilder builder) | ||
{ | ||
builder.AddDataLoader<global::TestNamespace.IEntityByIdDataLoader, global::TestNamespace.EntityByIdDataLoader>(); | ||
builder.Services.AddScoped<global::TestNamespace.IGroup1, global::TestNamespace.Group1>(); | ||
return builder; | ||
} | ||
} | ||
} | ||
|
||
``` | ||
|
129 changes: 129 additions & 0 deletions
129
...sts.GenerateSource_BatchDataLoader_With_Group_Only_On_Method_MatchesSnapshot.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
# GenerateSource_BatchDataLoader_With_Group_Only_On_Method_MatchesSnapshot | ||
|
||
## GreenDonutDataLoader.735550c.g.cs | ||
|
||
```csharp | ||
// <auto-generated/> | ||
#nullable enable | ||
#pragma warning disable | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using GreenDonut; | ||
|
||
namespace TestNamespace | ||
{ | ||
public interface IEntityByIdDataLoader | ||
: global::GreenDonut.IDataLoader<int, global::TestNamespace.Entity> | ||
{ | ||
} | ||
|
||
public sealed class EntityByIdDataLoader | ||
: global::GreenDonut.DataLoaderBase<int, global::TestNamespace.Entity> | ||
, IEntityByIdDataLoader | ||
{ | ||
private readonly global::System.IServiceProvider _services; | ||
|
||
public EntityByIdDataLoader( | ||
global::System.IServiceProvider services, | ||
global::GreenDonut.IBatchScheduler batchScheduler, | ||
global::GreenDonut.DataLoaderOptions options) | ||
: base(batchScheduler, options) | ||
{ | ||
_services = services ?? | ||
throw new global::System.ArgumentNullException(nameof(services)); | ||
} | ||
|
||
protected override async global::System.Threading.Tasks.ValueTask FetchAsync( | ||
global::System.Collections.Generic.IReadOnlyList<int> keys, | ||
global::System.Memory<GreenDonut.Result<global::TestNamespace.Entity?>> results, | ||
global::GreenDonut.DataLoaderFetchContext<global::TestNamespace.Entity> context, | ||
global::System.Threading.CancellationToken ct) | ||
{ | ||
var temp = await TestNamespace.TestClass.GetEntityByIdAsync(keys, ct).ConfigureAwait(false); | ||
CopyResults(keys, results.Span, temp); | ||
} | ||
|
||
private void CopyResults( | ||
global::System.Collections.Generic.IReadOnlyList<int> keys, | ||
global::System.Span<GreenDonut.Result<global::TestNamespace.Entity?>> results, | ||
global::System.Collections.Generic.IReadOnlyDictionary<int, TestNamespace.Entity> resultMap) | ||
{ | ||
for (var i = 0; i < keys.Count; i++) | ||
{ | ||
var key = keys[i]; | ||
if (resultMap.TryGetValue(key, out var value)) | ||
{ | ||
results[i] = global::GreenDonut.Result<global::TestNamespace.Entity?>.Resolve(value); | ||
} | ||
else | ||
{ | ||
results[i] = global::GreenDonut.Result<global::TestNamespace.Entity?>.Resolve(default(global::TestNamespace.Entity)); | ||
} | ||
} | ||
} | ||
} | ||
public interface IGroup1 | ||
{ | ||
IEntityByIdDataLoader EntityById { get; } | ||
} | ||
|
||
public sealed class Group1 : IGroup1 | ||
{ | ||
private readonly IServiceProvider _services; | ||
private IEntityByIdDataLoader? _entityById; | ||
|
||
public Group1(IServiceProvider services) | ||
{ | ||
_services = services | ||
?? throw new ArgumentNullException(nameof(services)); | ||
} | ||
public IEntityByIdDataLoader EntityById | ||
{ | ||
get | ||
{ | ||
if (_entityById is null) | ||
{ | ||
_entityById = _services.GetRequiredService<IEntityByIdDataLoader>(); | ||
} | ||
|
||
return _entityById!; | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
``` | ||
|
||
## HotChocolateTypeModule.735550c.g.cs | ||
|
||
```csharp | ||
// <auto-generated/> | ||
#nullable enable | ||
#pragma warning disable | ||
|
||
using System; | ||
using System.Runtime.CompilerServices; | ||
using HotChocolate; | ||
using HotChocolate.Types; | ||
using HotChocolate.Execution.Configuration; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public static partial class TestsTypesRequestExecutorBuilderExtensions | ||
{ | ||
public static IRequestExecutorBuilder AddTestsTypes(this IRequestExecutorBuilder builder) | ||
{ | ||
builder.AddDataLoader<global::TestNamespace.IEntityByIdDataLoader, global::TestNamespace.EntityByIdDataLoader>(); | ||
builder.Services.AddScoped<global::TestNamespace.IGroup1, global::TestNamespace.Group1>(); | ||
return builder; | ||
} | ||
} | ||
} | ||
|
||
``` | ||
|