Skip to content

Commit

Permalink
Support persisted documents
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 committed Aug 23, 2024
1 parent 8e52209 commit fd19d95
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Transports.AspNetCore/GraphQLHttpMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class GraphQLHttpMiddleware : IUserContextBuilder
private const string VARIABLES_KEY = "variables";
private const string EXTENSIONS_KEY = "extensions";
private const string OPERATION_NAME_KEY = "operationName";
private const string DOCUMENT_ID_KEY = "documentId";
private const string OPERATIONS_KEY = "operations"; // used for multipart/form-data requests per https://github.com/jaydenseric/graphql-multipart-request-spec
private const string MAP_KEY = "map"; // used for multipart/form-data requests per https://github.com/jaydenseric/graphql-multipart-request-spec
private const string MEDIATYPE_GRAPHQLJSON = "application/graphql+json"; // deprecated
Expand Down Expand Up @@ -343,8 +344,8 @@ void ApplyMapToRequests(Dictionary<string, string?[]> map, IFormCollection form,
foreach (var entry in map)
{
// validate entry key
if (entry.Key == "" || entry.Key == "query" || entry.Key == "operationName" || entry.Key == "variables" || entry.Key == "extensions" || entry.Key == "operations" || entry.Key == "map")
throw new InvalidMapError("Map key cannot be query, operationName, variables, extensions, operations or map.");
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)
throw new InvalidMapError("Map key cannot be query, operationName, variables, extensions, documentId, operations or map.");
// locate file
var file = form.Files[entry.Key]
?? throw new InvalidMapError("Map key does not refer to an uploaded file.");
Expand Down Expand Up @@ -1220,6 +1221,7 @@ protected virtual Task WriteErrorResponseAsync(HttpContext context, HttpStatusCo
Variables = formCollection.TryGetValue(VARIABLES_KEY, out var variablesValues) ? _serializer.Deserialize<Inputs>(variablesValues[0]) : null,
Extensions = formCollection.TryGetValue(EXTENSIONS_KEY, out var extensionsValues) ? _serializer.Deserialize<Inputs>(extensionsValues[0]) : null,
OperationName = formCollection.TryGetValue(OPERATION_NAME_KEY, out var operationNameValues) ? operationNameValues[0] : null,
DocumentId = formCollection.TryGetValue(DOCUMENT_ID_KEY, out var documentIdValues) ? documentIdValues[0] : null,
};

/// <summary>
Expand Down

0 comments on commit fd19d95

Please sign in to comment.