-
-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Schema Error Interceptor (#2581)
- Loading branch information
1 parent
421c765
commit 28f8695
Showing
8 changed files
with
184 additions
and
10 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
39 changes: 39 additions & 0 deletions
39
src/HotChocolate/Core/src/Types/Configuration/DelegateSchemaInterceptor.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,39 @@ | ||
using System; | ||
using HotChocolate.Types.Descriptors; | ||
|
||
#nullable enable | ||
|
||
namespace HotChocolate.Configuration | ||
{ | ||
public class DelegateSchemaInterceptor : SchemaInterceptor | ||
{ | ||
private readonly Action<IDescriptorContext, ISchemaBuilder>? _onBeforeCreate; | ||
private readonly Action<IDescriptorContext, ISchema>? _onAfterCreate; | ||
private readonly Action<IDescriptorContext, Exception>? _onError; | ||
|
||
public DelegateSchemaInterceptor( | ||
Action<IDescriptorContext, ISchemaBuilder>? onBeforeCreate = null, | ||
Action<IDescriptorContext, ISchema>? onAfterCreate = null, | ||
Action<IDescriptorContext, Exception>? onError = null) | ||
{ | ||
_onAfterCreate = onAfterCreate; | ||
_onBeforeCreate = onBeforeCreate; | ||
_onError = onError; | ||
} | ||
|
||
public override void OnBeforeCreate( | ||
IDescriptorContext context, | ||
ISchemaBuilder schemaBuilder) => | ||
_onBeforeCreate?.Invoke(context, schemaBuilder); | ||
|
||
public override void OnAfterCreate( | ||
IDescriptorContext context, | ||
ISchema schema) => | ||
_onAfterCreate?.Invoke(context, schema); | ||
|
||
public override void OnError( | ||
IDescriptorContext context, | ||
Exception exception) => | ||
_onError?.Invoke(context, exception); | ||
} | ||
} |
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