Esempio n. 1
0
        public async Task <ActionResult> GetPostPutDelete()
        {
            Body body = null;

            try
            {
                body = await GetBody();
            }
            catch (Exception e)
            {
                throw new Exception("Unable to deserialize body", e);
            }

            var graphqlResult = await new DocumentExecuter().ExecuteAsync(_ =>
            {
                _.Schema        = this.Schema;
                _.Query         = body.Query;
                _.Inputs        = body.Variables?.ToInputs();
                _.OperationName = body.OperationName;
                _.Listeners.Add(DataLoaderDocumentListener);

                // options.UserContext = userContext;
            }).ConfigureAwait(false);


            var json = new DocumentWriter(indent: true).Write(graphqlResult);

            var result = new ContentResult();

            result.ContentType = "application/json";
            //if there were no errors
            if (graphqlResult.Errors == null || graphqlResult.Errors.Count == 0)
            {
                result.StatusCode = (int)HttpStatusCode.OK;
            }
            else
            {
                //mark this response as an error
                result.StatusCode = (int)HttpStatusCode.InternalServerError;
                var o           = JsonConvert.DeserializeObject <JObject>(json);
                var errorsArray = (JArray)o.SelectToken("errors");
                errorsArray.RemoveAll();
                //append the actual errors into the list for more helpful debugging
                foreach (var error in graphqlResult.Errors)
                {
                    var prettyError = new PrettyError(error);
                    errorsArray.Add(JObject.Parse(JsonConvert.SerializeObject(prettyError)));
                }
                json = JsonConvert.SerializeObject(o);
            }
            result.Content = json;
            return(result);
        }
Esempio n. 2
0
 private void ObjectifyValue()
 {
     try
     {
         valueObj = null;
         if (json.GetValue() != null)
         {
             if (attribute.GetType().GetPrimitiveType() == JEVisConstants.PrimitiveType.DOUBLE)
             {
                 valueObj = Double.Parse(json.GetValue());
                 return;
             }
             else if (attribute.GetType().GetPrimitiveType() == JEVisConstants.PrimitiveType.LONG)
             {
                 valueObj = long.Parse(json.GetValue());
                 return;
             }
             else if (attribute.GetType().GetPrimitiveType() == JEVisConstants.PrimitiveType.BOOLEAN)
             {
                 valueObj = GetValueAsBool();
                 return;
             }
         }
         else
         {
             valueObj = null;
         }
     }
     catch (Exception ex)
     {
         logger.Error(string.Format("Error while casting Attribute Type: '{0}' in {1}", PrettyError.getJEVisLineFilter(ex), json));
         valueObj = null;
     }
     valueObj = json.GetValue();
 }