Skip to content

Commit c6c491c

Browse files
Make document Id available again in ParseDocument diagnostic event (#8760)
1 parent 0f64674 commit c6c491c

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ public async ValueTask InvokeAsync(RequestContext context)
4545
{
4646
documentInfo.Hash = CreateDocumentHash(documentInfo, context.Request);
4747
documentInfo.Document = parsed.Document;
48+
49+
if (documentInfo.Id.IsEmpty)
50+
{
51+
documentInfo.Id = new OperationDocumentId(documentInfo.Hash.Value);
52+
}
53+
4854
success = true;
4955
}
5056
else if (query is OperationDocumentSourceText source)
@@ -55,6 +61,12 @@ public async ValueTask InvokeAsync(RequestContext context)
5561
{
5662
documentInfo.Hash = CreateDocumentHash(documentInfo, context.Request);
5763
documentInfo.Document = Utf8GraphQLParser.Parse(source.SourceText, _parserOptions);
64+
65+
if (documentInfo.Id.IsEmpty)
66+
{
67+
documentInfo.Id = new OperationDocumentId(documentInfo.Hash.Value);
68+
}
69+
5870
success = true;
5971
}
6072
catch (SyntaxException ex)
@@ -80,11 +92,6 @@ public async ValueTask InvokeAsync(RequestContext context)
8092

8193
if (success)
8294
{
83-
if (documentInfo.Id.IsEmpty)
84-
{
85-
documentInfo.Id = new OperationDocumentId(documentInfo.Hash.Value);
86-
}
87-
8895
await _next(context).ConfigureAwait(false);
8996
}
9097
}

website/src/docs/hotchocolate/v16/migrating/migrate-from-15-to-16.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,36 @@ builder.Services.AddGraphQLServer()
3636
});
3737
```
3838

39+
## IRequestContext
40+
41+
We've removed the `IRequestContext` abstraction in favor of the concrete `RequestContext` class.
42+
Additionally, all information related to the parsed operation document has been consolidated into a new `OperationDocumentInfo` class, accessible via `RequestContext.OperationDocumentInfo`.
43+
44+
| Before | After |
45+
| --------------------------- | ----------------------------------------- |
46+
| context.DocumentId | context.OperationDocumentInfo.Id.Value |
47+
| context.Document | context.OperationDocumentInfo.Document |
48+
| context.DocumentHash | context.OperationDocumentInfo.Hash.Value |
49+
| context.ValidationResult | context.OperationDocumentInfo.IsValidated |
50+
| context.IsCachedDocument | context.OperationDocumentInfo.IsCached |
51+
| context.IsPersistedDocument | context.OperationDocumentInfo.IsPersisted |
52+
53+
Here's how you would update a custom request middleware implementation:
54+
55+
```diff
56+
public class CustomRequestMiddleware
57+
{
58+
- public async ValueTask InvokeAsync(IRequestContext context)
59+
+ public async ValueTask InvokeAsync(RequestContext context)
60+
{
61+
- string documentId = context.DocumentId;
62+
+ string documentId = context.OperationDocumentInfo.Id.Value;
63+
64+
await _next(context).ConfigureAwait(false);
65+
}
66+
}
67+
```
68+
3969
## Skip/include disallowed on root subscription fields
4070

4171
The `@skip` and `@include` directives are now disallowed on root subscription fields, as specified in the RFC: [Prevent @skip and @include on root subscription selection set](https://github.com/graphql/graphql-spec/pull/860).

0 commit comments

Comments
 (0)