Ejemplo n.º 1
0
 public async Task<IActionResult> Post([FromBody] GraphQLQuery query)
 {
     var result = await _executer.ExecuteAsync(_ =>
     {
         _.Schema = _schema; 
         return BadRequest();
     }
     return Ok(result.Data);
 }
Ejemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] GraphQLQuery query)
        {
            var result = await _executer.ExecuteAsync(_ =>
            {
                _.Schema = _schema;
            });

            if (result.Errors?.Count > 0)
            {
                return(BadRequest());
            }
            return(Ok(result.Data));
        }
        public async Task <HttpResponseMessage> PostAsync(HttpRequestMessage request, GraphQLQuery query)
        {
            var inputs         = query.Variables.ToInputs();
            var queryToExecute = query.Query;

            if (!string.IsNullOrWhiteSpace(query.NamedQuery))
            {
                queryToExecute = _namedQueries[query.NamedQuery];
            }

            var result = await new DocumentExecuter().ExecuteAsync(_ =>
            {
                _.Schema        = new AuthorsSchema();
                _.Query         = queryToExecute;
                _.OperationName = query.OperationName;
                _.Inputs        = inputs;

                _.ComplexityConfiguration = new ComplexityConfiguration {
                    MaxDepth = 15
                };
                _.FieldMiddleware.Use <InstrumentFieldsMiddleware>();
            }).ConfigureAwait(false);

            var httpResult = result.Errors?.Count > 0
                ? HttpStatusCode.BadRequest
                : HttpStatusCode.OK;

            var json = new DocumentWriter().Write(result);

            var response = request.CreateResponse(httpResult);

            response.Content = new StringContent(json, Encoding.UTF8, "application/json");

            return(response);
        }