-
-
Notifications
You must be signed in to change notification settings - Fork 744
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reworked Persisted Operation Options (#7560)
- Loading branch information
1 parent
b5f9d95
commit 0fc48ca
Showing
7 changed files
with
147 additions
and
83 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
53 changes: 53 additions & 0 deletions
53
...ests/__snapshots__/PersistedOperationTests.Ensure_Pooled_Objects_Are_Cleared.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,53 @@ | ||
# Ensure_Pooled_Objects_Are_Cleared | ||
|
||
## Result 1 - Should be OK | ||
|
||
```json | ||
{ | ||
"ContentType": "application/graphql-response+json; charset=utf-8", | ||
"StatusCode": "OK", | ||
"Data": { | ||
"hero": { | ||
"name": "R2-D2" | ||
} | ||
}, | ||
"Errors": null, | ||
"Extensions": null | ||
} | ||
``` | ||
|
||
## Result 2 - Should be OK | ||
|
||
```json | ||
{ | ||
"ContentType": "application/graphql-response+json; charset=utf-8", | ||
"StatusCode": "OK", | ||
"Data": { | ||
"hero": { | ||
"name": "R2-D2" | ||
} | ||
}, | ||
"Errors": null, | ||
"Extensions": null | ||
} | ||
``` | ||
|
||
## Result 3 - Should fail | ||
|
||
```json | ||
{ | ||
"ContentType": "application/graphql-response+json; charset=utf-8", | ||
"StatusCode": "BadRequest", | ||
"Data": null, | ||
"Errors": [ | ||
{ | ||
"message": "Only persisted operations are allowed.", | ||
"extensions": { | ||
"code": "HC0067" | ||
} | ||
} | ||
], | ||
"Extensions": null | ||
} | ||
``` | ||
|
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
37 changes: 24 additions & 13 deletions
37
src/HotChocolate/Core/src/Execution/Options/PersistedOperationOptions.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 |
---|---|---|
@@ -1,30 +1,41 @@ | ||
namespace HotChocolate.Execution.Options; | ||
|
||
/// <summary> | ||
/// Represents the options to configure the | ||
/// behavior of the persisted operation middleware. | ||
/// Represents the persisted operation options. | ||
/// </summary> | ||
[Flags] | ||
public enum PersistedOperationOptions | ||
public sealed class PersistedOperationOptions | ||
{ | ||
private IError _operationNotAllowedError = ErrorHelper.OnlyPersistedOperationsAreAllowed(); | ||
|
||
/// <summary> | ||
/// Nothing is configured. | ||
/// Specifies if only persisted operation documents are allowed. | ||
/// </summary> | ||
None = 0, | ||
public bool OnlyAllowPersistedDocuments { get; set; } | ||
|
||
/// <summary> | ||
/// Only persisted operations are allowed. | ||
/// Specifies that if <see cref="OnlyAllowPersistedDocuments"/> is switched on | ||
/// whether a standard GraphQL request with document body is allowed as long as | ||
/// it matches a persisted document. | ||
/// </summary> | ||
OnlyPersistedOperations = 1, | ||
public bool AllowDocumentBody { get; set; } | ||
|
||
/// <summary> | ||
/// Allow standard GraphQL requests if the GraphQL document | ||
/// match a persisted operation document. | ||
/// Specifies if persisted operation documents | ||
/// need to be validated. | ||
/// </summary> | ||
MatchStandardDocument = 2, | ||
public bool SkipPersistedDocumentValidation { get; set; } | ||
|
||
/// <summary> | ||
/// Skip validation for persisted operations documents. | ||
/// The error that will be thrown when only persisted | ||
/// operations are allowed and a normal operation is issued. | ||
/// </summary> | ||
SkipValidationForPersistedDocument = 4 | ||
public IError OperationNotAllowedError | ||
{ | ||
get => _operationNotAllowedError; | ||
set | ||
{ | ||
_operationNotAllowedError = value | ||
?? throw new ArgumentNullException(nameof(OperationNotAllowedError)); | ||
} | ||
} | ||
} |
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