-
-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into mst/frozen-field-collection
- Loading branch information
Showing
5 changed files
with
105 additions
and
12 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
43 changes: 43 additions & 0 deletions
43
src/HotChocolate/Data/src/EntityFramework/InferDbContextParameterExpressionBuilder.cs
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,43 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Reflection; | ||
using HotChocolate.Internal; | ||
using HotChocolate.Resolvers.Expressions.Parameters; | ||
using HotChocolate.Types; | ||
using HotChocolate.Types.Descriptors; | ||
using HotChocolate.Types.Descriptors.Definitions; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace HotChocolate.Data; | ||
|
||
internal sealed class InferDbContextParameterExpressionBuilder() | ||
: IParameterExpressionBuilder | ||
, IParameterFieldConfiguration | ||
{ | ||
public ArgumentKind Kind => ArgumentKind.Service; | ||
|
||
public bool IsPure => false; | ||
|
||
public bool IsDefaultHandler => false; | ||
|
||
public bool CanHandle(ParameterInfo parameter) | ||
=> typeof(DbContext).IsAssignableFrom(parameter.ParameterType); | ||
|
||
public void ApplyConfiguration(ParameterInfo parameter, ObjectFieldDescriptor descriptor) | ||
{ | ||
ServiceExpressionHelper.ApplyConfiguration(parameter, descriptor, ServiceKind.Resolver); | ||
var definition = descriptor.Extend().Definition; | ||
var placeholderMiddleware = new FieldMiddlewareDefinition( | ||
_ => _ => throw new NotSupportedException(), | ||
key: WellKnownMiddleware.ToList); | ||
var serviceMiddleware = | ||
definition.MiddlewareDefinitions.Last(t => t.Key == WellKnownMiddleware.ResolverService); | ||
var index = definition.MiddlewareDefinitions.IndexOf(serviceMiddleware) + 1; | ||
definition.MiddlewareDefinitions.Insert(index, placeholderMiddleware); | ||
EntityFrameworkObjectFieldDescriptorExtensions.AddCompletionMiddleware(definition, placeholderMiddleware); | ||
} | ||
|
||
public Expression Build(ParameterExpressionBuilderContext context) | ||
=> ServiceExpressionHelper.Build(context.Parameter, context.ResolverContext, ServiceKind.Resolver); | ||
} |
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
15 changes: 15 additions & 0 deletions
15
...lerIntegrationTests.Resolver_Pipeline_With_Field_AutoRegistered_DbContext_Is_Created.snap
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,15 @@ | ||
{ | ||
"data": { | ||
"books": [ | ||
{ | ||
"title": "Foo1" | ||
}, | ||
{ | ||
"title": "Bar1" | ||
}, | ||
{ | ||
"title": "Baz1" | ||
} | ||
] | ||
} | ||
} |