Ejemplo n.º 1
0
        private async Task <IActionResult> ExecuteInternal(GraphQLRequest gqlRequest, string appId)
        {
            var schema = await _schemaResolver.Resolve(appId);

            if (schema == null)
            {
                return(BadRequest($"No schema for {appId} could be resolved"));
            }


            var result = await _executer.ExecuteAsync(options =>
            {
                options.Schema        = schema;
                options.Query         = gqlRequest.Query;
                options.OperationName = gqlRequest.OperationName;
                options.Inputs        = gqlRequest.GetInputs();

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

            var json = await _writer.WriteToStringAsync(result);

            var actionResult = new ContentResult
            {
                ContentType = JsonContentType,
                Content     = json,
                StatusCode  = result.Errors == null || result.Errors.Count == 0 ? (int)HttpStatusCode.OK : (int)HttpStatusCode.BadRequest
            };

            return(actionResult);
        }