Exemple #1
0
        private GraphQLError AddBadRequestError(string message)
        {
            var err = new GraphQLError(message, null, SourceLocation.StartLocation, ErrorCodes.BadRequest);

            _requestContext.AddError(err);
            return(err);
        }
Exemple #2
0
 public async Task ExecuteRequestAsync(RequestContext context)
 {
     try {
         // validate
         if (string.IsNullOrWhiteSpace(context.RawRequest.Query))
         {
             throw new GraphQLException("Query may not be empty.");
         }
         Events.OnRequestStarting(context);
         var handler = new RequestHandler(this, context);
         await handler.ExecuteAsync();
     } catch (AbortRequestException) {
         return; // error already added to response
     } catch (InvalidInputException inpEx) {
         context.AddInputError(inpEx);
     } catch (Exception ex) {
         context.AddError(ex);
     } finally {
         context.Metrics.Duration = AppTime.GetDuration(context.StartTimestamp);
         if (context.Failed)
         {
             Events.OnRequestError(context);
         }
         Events.OnRequestCompleted(context);
     }
 }
Exemple #3
0
        private void AddError(string message, RequestObjectBase item, string errorType = ErrorCodes.BadRequest)
        {
            var path = item.GetRequestObjectPath();
            var err  = new GraphQLError(message, path, item.SourceLocation, errorType);

            _requestContext.AddError(err);
        }
Exemple #4
0
        private void AddError(string message, ParseTreeNode node)
        {
            var path = _path.ToArray().Reverse().ToArray();
            var loc  = node?.GetLocation() ?? SourceLocation.StartLocation;
            var err  = new GraphQLError(message, path, loc, ErrorCodes.BadRequest);

            _requestContext.AddError(err);
        }
Exemple #5
0
        private ParseTree ParseToSyntaxTree(string query)
        {
            var syntaxParser = _requestContext.Server.Grammar.CreateRequestParser();
            var parseTree    = syntaxParser.Parse(query);

            if (parseTree.HasErrors())
            {
                // copy errors to response and return
                foreach (var errMsg in parseTree.ParserMessages)
                {
                    var loc = errMsg.Location.ToLocation();
                    // we cannot retrieve path here, parser failed early, so no parse tree - this is Irony's limitation, to be fixed
                    IList <object> noPath = null;
                    var            err    = new GraphQLError("Query parsing failed: " + errMsg.Message, noPath, loc, ErrorCodes.Syntax);
                    _requestContext.AddError(err);
                }
            }
            return(parseTree);
        }
Exemple #6
0
        private void AddError(RequestContext context, string message, IList <object> path)
        {
            var err = new GraphQLError()
            {
                Message = "Variables: " + message,
                Path    = path
            };

            context.AddError(err);
        }
Exemple #7
0
 private void AddError(string message, RequestObjectBase item, string errorType = ErrorCodes.BadRequest)
 {
     _requestContext.AddError(message, item, errorType);
 }