private async Task <GraphQLHttpRequest> BuildPostRequestAsync(HttpContext httpContext) { var req = new GraphQLRequest(); var httpReq = new GraphQLHttpRequest() { HttpContext = httpContext, HttpMethod = "POST", Request = req }; // read body var reader = new StreamReader(httpContext.Request.Body); var body = await reader.ReadToEndAsync(); httpReq.ContentType = GetRequestContentType(httpContext.Request); switch (httpReq.ContentType) { case HttpContentType.GraphQL: req.Query = body; break; case HttpContentType.Json: var bodyObj = Deserialize <GraphQLRequest>(body); req.Query = bodyObj.Query; req.OperationName = bodyObj.OperationName; req.Variables = bodyObj.Variables; break; } // still check 'query' parameter in URL and overwrite query in body if found var urlQry = httpContext.Request.Query; var urlQryPrm = urlQry["query"]; if (!string.IsNullOrEmpty(urlQryPrm)) { req.Query = urlQryPrm; } return(httpReq); }//method
private GraphQLHttpRequest BuildGetRequest(HttpContext httpContext) { var uriQuery = httpContext.Request.Query; var gqlRequest = new GraphQLRequest() { Query = uriQuery["query"], OperationName = uriQuery["operationName"] }; var varsJson = uriQuery["variables"]; if (!string.IsNullOrWhiteSpace(varsJson)) { gqlRequest.Variables = Deserialize <IDictionary <string, object> >(varsJson); } var httpReq = new GraphQLHttpRequest() { HttpContext = httpContext, HttpMethod = "GET", Request = gqlRequest, ContentType = HttpContentType.None, //no body }; return(httpReq); }