Skip to content

Commit 277e886

Browse files
committed
Add test for redis cache key
(cherry picked from commit 490ffcd6adc446222a7ff9a67edeaad20ed6649a) (cherry picked from commit d59b0ad448b5a2a979f5d42f43fb5468de980eab)
1 parent 31b1ee7 commit 277e886

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/HotChocolate/PersistedOperations/test/PersistedOperations.Redis.Tests/IntegrationTests.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,46 @@ await storage.SaveAsync(
5757
result.MatchSnapshot();
5858
}
5959

60+
[Fact]
61+
public async Task ExecutePersistedOperation_With_CacheKeyPrefix()
62+
{
63+
// arrange
64+
const string cacheKeyPrefix = "test-prefix";
65+
var documentId = new OperationDocumentId(Guid.NewGuid().ToString("N"));
66+
var storage = new RedisOperationDocumentStorage(_database, cacheKeyPrefix: cacheKeyPrefix);
67+
68+
await storage.SaveAsync(
69+
documentId,
70+
new OperationDocumentSourceText("{ __typename }"));
71+
72+
var executor =
73+
await new ServiceCollection()
74+
.AddGraphQL()
75+
.AddQueryType(c => c.Name("Query").Field("a").Resolve("b"))
76+
.AddRedisOperationDocumentStorage(_ => _database, cacheKeyPrefix: cacheKeyPrefix)
77+
.UseRequest((_, n) => async c =>
78+
{
79+
await n(c);
80+
81+
var documentInfo = c.OperationDocumentInfo;
82+
if (documentInfo.Id == documentId && c.Result is IOperationResult r)
83+
{
84+
c.Result = OperationResultBuilder
85+
.FromResult(r)
86+
.SetExtension("persistedDocument", true)
87+
.Build();
88+
}
89+
})
90+
.UsePersistedOperationPipeline()
91+
.BuildRequestExecutorAsync();
92+
93+
// act
94+
var result = await executor.ExecuteAsync(OperationRequest.FromId(documentId));
95+
96+
// assert
97+
result.MatchSnapshot();
98+
}
99+
60100
[Fact]
61101
public async Task ExecutePersistedOperation_After_Expiration()
62102
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"data": {
3+
"__typename": "Query"
4+
},
5+
"extensions": {
6+
"persistedDocument": true
7+
}
8+
}

0 commit comments

Comments
 (0)