-
-
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.
feat(Core): adds scoped data context (#538)
- Loading branch information
1 parent
00b2e5a
commit 7b106aa
Showing
8 changed files
with
88 additions
and
5 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/Core/Core.Tests/Execution/Middleware/ScopedContextDataTests.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,46 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using ChilliCream.Testing; | ||
using Xunit; | ||
|
||
namespace HotChocolate.Execution | ||
{ | ||
public class ScopedContextDataTests | ||
{ | ||
[Fact] | ||
public async Task ScopedContextDataIsPassedAllongCorrectly() | ||
{ | ||
// arrange | ||
bool allDataIsPassedAlong = false; | ||
|
||
ISchema schema = Schema.Create( | ||
"type Query { nested: Nested } type Nested { foo: String }", | ||
c => c.Use(next => context => | ||
{ | ||
if (context.ScopedContextData.ContainsKey("field")) | ||
{ | ||
allDataIsPassedAlong = true; | ||
context.Result = "123"; | ||
} | ||
else | ||
{ | ||
context.ScopedContextData = context.ScopedContextData.Add("field", "abc"); | ||
context.Result = new { foo = "123"}; | ||
} | ||
|
||
return Task.CompletedTask; | ||
})); | ||
|
||
IQueryExecutor executor = schema.MakeExecutable( | ||
b => b.UseDefaultPipeline() | ||
); | ||
|
||
// act | ||
IExecutionResult result = await executor.ExecuteAsync( | ||
new QueryRequest("{ nested { foo } }")); | ||
|
||
// assert | ||
Assert.True(allDataIsPassedAlong); | ||
} | ||
} | ||
} |
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
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