@@ -67,6 +67,7 @@ public class GraphQLHttpMiddleware : IUserContextBuilder
67
67
private const string VARIABLES_KEY = "variables" ;
68
68
private const string EXTENSIONS_KEY = "extensions" ;
69
69
private const string OPERATION_NAME_KEY = "operationName" ;
70
+ private const string DOCUMENT_ID_KEY = "documentId" ;
70
71
private const string OPERATIONS_KEY = "operations" ; // used for multipart/form-data requests per https://github.com/jaydenseric/graphql-multipart-request-spec
71
72
private const string MAP_KEY = "map" ; // used for multipart/form-data requests per https://github.com/jaydenseric/graphql-multipart-request-spec
72
73
private const string MEDIATYPE_GRAPHQLJSON = "application/graphql+json" ;
@@ -174,7 +175,8 @@ public virtual async Task InvokeAsync(HttpContext context)
174
175
Query = urlGQLRequest ? . Query ?? bodyGQLRequest ? . Query ,
175
176
Variables = urlGQLRequest ? . Variables ?? bodyGQLRequest ? . Variables ,
176
177
Extensions = urlGQLRequest ? . Extensions ?? bodyGQLRequest ? . Extensions ,
177
- OperationName = urlGQLRequest ? . OperationName ?? bodyGQLRequest ? . OperationName
178
+ OperationName = urlGQLRequest ? . OperationName ?? bodyGQLRequest ? . OperationName ,
179
+ DocumentId = urlGQLRequest ? . DocumentId ?? bodyGQLRequest ? . DocumentId ,
178
180
} ;
179
181
180
182
await HandleRequestAsync ( context , _next , gqlRequest ) ;
@@ -299,8 +301,8 @@ void ApplyMapToRequests(Dictionary<string, string?[]> map, IFormCollection form,
299
301
300
302
foreach ( var entry in map ) {
301
303
// validate entry key
302
- if ( entry . Key == "" || entry . Key == "query" || entry . Key == "operationName" || entry . Key == "variables" || entry . Key == "extensions" || entry . Key == "operations" || entry . Key == "map" )
303
- throw new InvalidMapError ( "Map key cannot be query, operationName, variables, extensions, operations or map." ) ;
304
+ if ( entry . Key == "" || entry . Key == QUERY_KEY || entry . Key == OPERATION_NAME_KEY || entry . Key == VARIABLES_KEY || entry . Key == EXTENSIONS_KEY || entry . Key == DOCUMENT_ID_KEY || entry . Key == OPERATIONS_KEY || entry . Key == MAP_KEY )
305
+ throw new InvalidMapError ( "Map key cannot be query, operationName, variables, extensions, documentId, operations or map." ) ;
304
306
// locate file
305
307
var file = form . Files [ entry . Key ]
306
308
?? throw new InvalidMapError ( "Map key does not refer to an uploaded file." ) ;
@@ -603,6 +605,7 @@ protected virtual async Task<ExecutionResult> ExecuteRequestAsync(HttpContext co
603
605
Query = request ? . Query ,
604
606
Variables = request ? . Variables ,
605
607
Extensions = request ? . Extensions ,
608
+ DocumentId = request ? . DocumentId ,
606
609
CancellationToken = context . RequestAborted ,
607
610
OperationName = request ? . OperationName ,
608
611
RequestServices = serviceProvider ,
@@ -884,13 +887,15 @@ protected virtual Task WriteErrorResponseAsync(HttpContext context, HttpStatusCo
884
887
Variables = _options . ReadVariablesFromQueryString && queryCollection . TryGetValue ( VARIABLES_KEY , out var variablesValues ) ? _serializer . Deserialize < Inputs > ( variablesValues [ 0 ] ) : null ,
885
888
Extensions = _options . ReadExtensionsFromQueryString && queryCollection . TryGetValue ( EXTENSIONS_KEY , out var extensionsValues ) ? _serializer . Deserialize < Inputs > ( extensionsValues [ 0 ] ) : null ,
886
889
OperationName = queryCollection . TryGetValue ( OPERATION_NAME_KEY , out var operationNameValues ) ? operationNameValues [ 0 ] : null ,
890
+ DocumentId = queryCollection . TryGetValue ( DOCUMENT_ID_KEY , out var documentIdValues ) ? documentIdValues [ 0 ] : null ,
887
891
} ;
888
892
889
893
private GraphQLRequest DeserializeFromFormBody ( IFormCollection formCollection ) => new ( ) {
890
894
Query = formCollection . TryGetValue ( QUERY_KEY , out var queryValues ) ? queryValues [ 0 ] : null ,
891
895
Variables = formCollection . TryGetValue ( VARIABLES_KEY , out var variablesValues ) ? _serializer . Deserialize < Inputs > ( variablesValues [ 0 ] ) : null ,
892
896
Extensions = formCollection . TryGetValue ( EXTENSIONS_KEY , out var extensionsValues ) ? _serializer . Deserialize < Inputs > ( extensionsValues [ 0 ] ) : null ,
893
897
OperationName = formCollection . TryGetValue ( OPERATION_NAME_KEY , out var operationNameValues ) ? operationNameValues [ 0 ] : null ,
898
+ DocumentId = formCollection . TryGetValue ( DOCUMENT_ID_KEY , out var documentIdValues ) ? documentIdValues [ 0 ] : null ,
894
899
} ;
895
900
896
901
/// <summary>
0 commit comments