Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't set context.Result to null on error detection #46

Closed
benmccallum opened this issue Jun 8, 2021 · 1 comment
Closed

Don't set context.Result to null on error detection #46

benmccallum opened this issue Jun 8, 2021 · 1 comment
Assignees
Milestone

Comments

@benmccallum
Copy link
Owner

Request from @m.webert in Slack.

Potentially via a setting that defaults to current behaviour, as a minor release, then we can swap over in next major release the default.

@benmccallum
Copy link
Owner Author

benmccallum commented Jun 14, 2021

Released in 6.1.0. Thanks to @markuswebert for the PR!

Unit test example of what this unlocks:

[Theory]
[InlineData(false)]
[InlineData(true)]
public async Task Should_Respect_SetNullResultOnValidationError_Option(bool setNullResultOnValidationError)
{
// Arrange
var executor = await GetRequestExecutorAsync(
options =>
{
options.SetNullResultOnValidationError = setNullResultOnValidationError;
options.ShouldValidate = (ctx, arg) => ctx.Operation.Operation == OperationType.Query;
},
services =>
{
// Support those wanting to write data to context.Result in a custom
// `IValidationErrorsHandler` implementation
if (!setNullResultOnValidationError)
{
services.AddSingleton<IValidationErrorsHandler, CustomValidationErrorsHandler>();
}
});
var query = @"query { read(foo: { someInteger: -1, someString: ""hello"" }) }";
// Act
var result = await executor.ExecuteAsync(query);
// Assert
var verifySettings = new VerifySettings();
verifySettings.UseParameters(setNullResultOnValidationError);
await Verifier.Verify(result, verifySettings);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant