Skip to content

Commit 94aae4d

Browse files
authored
Added event hook for document not found in storage. (#7596)
1 parent 805ee45 commit 94aae4d

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

src/HotChocolate/Core/src/Execution/Instrumentation/AggregateExecutionDiagnosticEvents.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,16 @@ public void RetrievedDocumentFromStorage(IRequestContext context)
308308
}
309309
}
310310

311+
public void DocumentNotFoundInStorage(
312+
IRequestContext context,
313+
OperationDocumentId documentId)
314+
{
315+
for (var i = 0; i < _listeners.Length; i++)
316+
{
317+
_listeners[i].DocumentNotFoundInStorage(context, documentId);
318+
}
319+
}
320+
311321
public void AddedOperationToCache(IRequestContext context)
312322
{
313323
for (var i = 0; i < _listeners.Length; i++)

src/HotChocolate/Core/src/Execution/Instrumentation/ExecutionDiagnosticEventListener.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,13 @@ public virtual void RetrievedDocumentFromStorage(IRequestContext context)
164164
{
165165
}
166166

167+
/// <inheritdoc />
168+
public virtual void DocumentNotFoundInStorage(
169+
IRequestContext context,
170+
OperationDocumentId documentId)
171+
{
172+
}
173+
167174
/// <inheritdoc />
168175
public virtual void AddedOperationToCache(IRequestContext context)
169176
{

src/HotChocolate/Core/src/Execution/Instrumentation/IExecutionDiagnosticEvents.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,19 @@ public interface IExecutionDiagnosticEvents
352352
/// <param name="context"></param>
353353
void RetrievedDocumentFromStorage(IRequestContext context);
354354

355+
/// <summary>
356+
/// Called when the document for a persisted operation could not be found in the
357+
/// operation document storage.
358+
/// </summary>
359+
/// <param name="context">
360+
/// The request context encapsulates all GraphQL-specific information
361+
/// about an individual GraphQL request.
362+
/// </param>
363+
/// <param name="documentId">
364+
/// The document id that was not found in the storage.
365+
/// </param>
366+
void DocumentNotFoundInStorage(IRequestContext context, OperationDocumentId documentId);
367+
355368
/// <summary>
356369
/// A compiled operation was added to the operation cache.
357370
/// </summary>

src/HotChocolate/Core/src/Execution/Instrumentation/NoopExecutionDiagnosticEvents.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ public void RetrievedDocumentFromStorage(IRequestContext context)
101101
{
102102
}
103103

104+
public void DocumentNotFoundInStorage(IRequestContext context, OperationDocumentId documentId)
105+
{
106+
}
107+
104108
public void AddedOperationToCache(IRequestContext context)
105109
{
106110
}

src/HotChocolate/Core/src/Execution/Pipeline/PersistedOperationNotFoundMiddleware.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ public ValueTask InvokeAsync(IRequestContext context)
2727
return _next(context);
2828
}
2929

30+
// we know that the key is not null since otherwise the request would have
31+
// failed already since no operation is specified.
3032
var requestedKey =
31-
context.Request.DocumentId ??
33+
(context.Request.DocumentId ??
3234
context.DocumentId ??
3335
context.DocumentHash ??
34-
context.Request.DocumentHash;
36+
context.Request.DocumentHash)!.Value;
3537

36-
// we know that the key is not null since otherwise the request would have
37-
// failed already since no operation is specified.
38-
var error = ErrorHelper.PersistedOperationNotFound(requestedKey!.Value);
38+
_diagnosticEvents.DocumentNotFoundInStorage(context, requestedKey);
39+
var error = ErrorHelper.PersistedOperationNotFound(requestedKey);
3940
_diagnosticEvents.RequestError(context, new GraphQLException(error));
4041
context.Result = OperationResultBuilder.CreateError(error, _statusCode);
4142

0 commit comments

Comments
 (0)