示例#1
0
        public static async Task <GraphQLResponse> ExecuteAsync(string query, IDictionary <string, object> variables = null, bool throwOnError = true)
        {
            GraphQLResponse resp = null;

            try {
                var req = new GraphQLRequest()
                {
                    Query = query, Variables = variables
                };
                resp = await ThingsServer.ExecuteAsync(req);

                if (!resp.IsSuccess())
                {
                    var errText = resp.GetErrorsAsText();
                    Debug.WriteLine("Errors: \r\n" + errText);
                }
            } catch (Exception ex) {
                TestEnv.LogException(query, ex);
                throw;
            }
            if (resp != null && resp.Errors != null && resp.Errors.Count > 0 && throwOnError)
            {
                throw new Exception($"Request failed: {resp.Errors[0].Message}");
            }
            return(resp);
        }
 public static string GetErrorsAsText(this GraphQLResponse response)
 {
     if (response.IsSuccess())
     {
         return(string.Empty);
     }
     return(string.Join(Environment.NewLine, response.Errors));
 }