Exemple #1
0
        public async Task <dynamic> PostAsync(GraphQLQuery query)
        {
            var inputs         = query.Variables.ToInputs();
            var queryToExecute = query.Query;

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

            var result = await _executer.ExecuteAsync(_ =>
            {
                _.Schema                  = _schema;
                _.Query                   = queryToExecute;
                _.OperationName           = query.OperationName;
                _.Inputs                  = inputs;
                _.ComplexityConfiguration = new ComplexityConfiguration {
                    MaxDepth = 15
                };
                _.FieldMiddleware.Use <InstrumentFieldsMiddleware>();
                _.ValidationRules = _validationRules.Concat(DocumentValidator.CoreRules());
            }).ConfigureAwait(false);

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



            if (httpResult != HttpStatusCode.OK)
            {
                throw new Exception(result.Errors.First().Message);
            }
            var     json = _writer.Write(result);
            dynamic obj  = Newtonsoft.Json.JsonConvert.DeserializeObject <dynamic>(json);

            return(obj);
        }
Exemple #2
0
        public async Task <dynamic> PostAsync([CommandParameter(FromBody = true)] GraphQLQuery body)
        {
            var graphQLRequestHandler = TheContainer.Resolve <GraphQLRequestHandler>();

            return(await graphQLRequestHandler.PostAsync(body));
        }