-
-
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.
Fixed: ResolverResult value constructor ignores value parameter (#217)
- Loading branch information
1 parent
62afad5
commit 8206934
Showing
7 changed files
with
236 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,43 @@ | ||
namespace HotChocolate | ||
{ | ||
/// <summary> | ||
/// A resolver result represents an error or a value that is returned by the | ||
/// field resolver. This interface provides a way to path field errors to | ||
/// the execution engine without throwing QueryExceptions. | ||
/// </summary> | ||
public interface IResolverResult | ||
{ | ||
/// <summary> | ||
/// The error message that shall be used to create a | ||
/// field error if the resolver result represents an error. | ||
/// </summary> | ||
string ErrorMessage { get; } | ||
|
||
/// <summary> | ||
/// Defines if the resolver result instance represents | ||
/// an error <c>true</c> or a value <c>false</c>. | ||
/// </summary> | ||
bool IsError { get; } | ||
|
||
/// <summary> | ||
/// The resolver result value that shall be processed by the | ||
/// execution engine in case this resolver is not an error. | ||
/// </summary> | ||
object Value { get; } | ||
} | ||
|
||
/// <summary> | ||
/// A resolver result represents an error or a value that is returned by the | ||
/// field resolver. This interface provides a way to path field errors to | ||
/// the execution engine without throwing QueryExceptions. | ||
/// </summary> | ||
public interface IResolverResult<out TValue> | ||
: IResolverResult | ||
{ | ||
/// <summary> | ||
/// The resolver result value that shall be processed by the | ||
/// execution engine in case this resolver is not an error. | ||
/// </summary> | ||
new TValue Value { get; } | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using Xunit; | ||
|
||
namespace HotChocolate | ||
{ | ||
public class ResolverResultTests | ||
{ | ||
[Fact] | ||
public void CreateValue() | ||
{ | ||
// arrange | ||
string value = Guid.NewGuid().ToString(); | ||
|
||
// act | ||
var result = ResolverResult<string>.CreateValue(value); | ||
|
||
// assert | ||
Assert.Equal(value, result.Value); | ||
Assert.False(result.IsError); | ||
Assert.Null(result.ErrorMessage); | ||
} | ||
|
||
[Fact] | ||
public void CreateError() | ||
{ | ||
// arrange | ||
string errorMessage = Guid.NewGuid().ToString(); | ||
|
||
// act | ||
var result = ResolverResult<string>.CreateError(errorMessage); | ||
|
||
// assert | ||
Assert.Equal(errorMessage, result.ErrorMessage); | ||
Assert.True(result.IsError); | ||
Assert.Null(result.Value); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/Core.Tests/__snapshots__/ExecuteFieldWithResolverResult.json
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,7 @@ | ||
{ | ||
"Data": { | ||
"x": "hello world x", | ||
"xasync": "hello world xasync" | ||
}, | ||
"Errors": null | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Core.Tests/__snapshots__/ExecuteFieldWithResolverResultError.json
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,28 @@ | ||
{ | ||
"Data": { | ||
"y": null, | ||
"yasync": null | ||
}, | ||
"Errors": [ | ||
{ | ||
"FieldName": "y", | ||
"Locations": [ | ||
{ | ||
"Line": 1, | ||
"Column": 3 | ||
} | ||
], | ||
"Message": "hello world y" | ||
}, | ||
{ | ||
"FieldName": "yasync", | ||
"Locations": [ | ||
{ | ||
"Line": 1, | ||
"Column": 5 | ||
} | ||
], | ||
"Message": "hello world yasync" | ||
} | ||
] | ||
} |
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