public void Equality2Fact()
        {
            var graphQLError1 = new GraphQLError("message");
            var graphQLError2 = new GraphQLError("message");

            Assert.Equal(graphQLError1, graphQLError2);
        }
        public void InEquality1Fact()
        {
            var graphQLError1 = new GraphQLError("message1");
            var graphQLError2 = new GraphQLError("message2");

            Assert.NotEqual(graphQLError1, graphQLError2);
        }
Example #3
0
        public void AddError(string message, RequestObjectBase item, string errorType = ErrorCodes.BadRequest)
        {
            var path = item.GetRequestObjectPath();
            var err  = new GraphQLError(message, path, item.SourceLocation, errorType);

            AddError(err);
        }
Example #4
0
        private GraphQLError AddVariableError(string message)
        {
            var err = new GraphQLError(message, null, SourceLocation.StartLocation, ErrorCodes.InputError);

            _requestContext.AddError(err);
            return(err);
        }
        public static void AddInputError(this IRequestContext context, InvalidInputException exc)
        {
            var path = exc.Anchor.GetRequestObjectPath();
            var loc  = exc.Anchor.SourceLocation;
            var err  = new GraphQLError(exc.Message, path, loc, ErrorCodes.InputError);

            context.AddError(err);
        }
        public static void AddInputError(this RequestContext context, string message, RequestObjectBase anchor)
        {
            var path = anchor.GetRequestObjectPath();
            var loc  = anchor.SourceLocation;
            var err  = new GraphQLError(message, path, loc, ErrorCodes.InputError);

            context.AddError(err);
        }
Example #7
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);
        }
        internal static void ThrowRequestCancelled(this FieldContext fieldContext)
        {
            var reqCtx = (RequestContext)fieldContext.RequestContext;
            var err    = new GraphQLError($"Request cancelled",
                                          fieldContext.GetFullRequestPath(), fieldContext.SelectionField.SourceLocation, type: "Cancel");

            reqCtx.AddError(err);
            throw new AbortRequestException();
        }
        public void ConstructorFact()
        {
            var graphQLError = new GraphQLError("message");

            Assert.NotNull(graphQLError.Message);
            Assert.Null(graphQLError.Extensions);
            Assert.Null(graphQLError.Locations);
            Assert.Null(graphQLError.Path);
        }
        internal static void ThrowObjectCountExceededQuota(this FieldContext fieldContext)
        {
            var reqCtx = (RequestContext)fieldContext.RequestContext;
            var quota  = reqCtx.Quota;
            var err    = new GraphQLError($"Output object count exceeded maximum ({quota.MaxOutputObjects}) allowed by quota.",
                                          fieldContext.GetFullRequestPath(), fieldContext.SelectionField.SourceLocation, type: "Quota");

            reqCtx.AddError(err);
            throw new AbortRequestException();
        }
Example #11
0
        private void AddError(RequestContext context, string message, IList <object> path)
        {
            var err = new GraphQLError()
            {
                Message = "Variables: " + message,
                Path    = path
            };

            context.AddError(err);
        }
Example #12
0
        public void ThrowExceptionIfGraphQLErrorResponseHasError_whenErrorExceptionIsNull_throwsUnexpectedException()
        {
            GraphQLError    error    = new GraphQLError();
            GraphQLResponse response = new GraphQLResponse();

            response.errors = new List <GraphQLError>();
            response.errors.Add(new GraphQLError());

            Assert.Throws <UnexpectedException> (() => BraintreeGraphQLService.ThrowExceptionIfGraphQLErrorResponseHasError(response));
        }
Example #13
0
 private void OnCancelled()
 {
     if (!_externalCancelled)
     {
         // we assume it's timeout, token is already signaling; add error
         var err = new GraphQLError(
             $"Request canceled, request time exceeded max specified by quota ({Quota.MaxOutputObjects}).", type: "Quota");
         AddError(err);
     }
 }
        public static GraphQLError AddError(this IFieldContext fieldContext, string message,
                                            string type = ErrorCodes.InputError)
        {
            var loc  = fieldContext.SelectionField.SourceLocation;
            var path = fieldContext.GetFullRequestPath();
            var err  = new GraphQLError(message, path, loc, type);

            fieldContext.AddError(err);
            return(err);
        }
Example #15
0
 public void AddError(GraphQLError error, Exception sourceException = null)
 {
     lock (this.Lock) {
         this.Response.Errors.Add(error);
         if (sourceException != null)
         {
             this.Exceptions.Add(sourceException);
         }
         this.Failed = true;
     }
 }
Example #16
0
        internal static void ThrowFieldDepthExceededQuota(this FieldContext fieldContext)
        {
            var reqCtx    = (RequestContext)fieldContext.RequestContext;
            var quota     = reqCtx.Quota;
            var sourceLoc = fieldContext.SourceLocation;
            var err       = new GraphQLError($"Query depth exceeded maximum ({quota.MaxDepth}) allowed by quota.",
                                             fieldContext.GetFullRequestPath(), sourceLoc, type: "Quota");

            reqCtx.AddError(err);
            throw new AbortRequestException();
        }
        public async Task <IActionResult> Post([FromBody] GraphQLQuery query)
        {
            this._schemaFactory.WithHttpRequest(this.Request)
            .DefinePolicy();

            if (this._schemaFactory.Type == EPolicyType.Unknown)
            {
                return(this.BadRequest());
            }

            var executionOptions = new ExecutionOptions
            {
                Schema      = this._schemaFactory.ProvideSchema(),
                Query       = query.Query,
                Inputs      = query.Variables.ToInputs(),
                UserContext = this._schemaFactory.ProvideContext(),
            };

            var result = await this._documentExecuter.ExecuteAsync(executionOptions).ConfigureAwait(false);

            if (result.Errors?.Count > 0)
            {
                var response = new GraphQLError
                {
                    Message = "Internal server error: ",
                    Code    = 500
                };
                result.Errors?.ForEach(c =>
                {
                    if (c.InnerException != null && c.InnerException is AmazingException exception)
                    {
                        response.Message = exception.Message;
                        response.Code    = (int)exception.Status;
                    }
                    else if (c.InnerException != null)
                    {
                        response.Message = c.InnerException.Message;
                    }
                    else
                    {
                        response.Message += c.Message;
                    }
                });

                return(Ok(new
                {
                    errors = new List <GraphQLError> {
                        response
                    }
                }));
            }

            return(this.Ok(result));
        }
        public static GraphQLError AddError(this RequestContext requestContext, Exception exc,
                                            IList <object> path = null, SourceLocation location = null)
        {
            var err     = new GraphQLError(exc.Message, path, location, ErrorCodes.ServerError);
            var withDet = requestContext.Server.Settings.Options.IsSet(GraphQLServerOptions.ReturnExceptionDetails);

            if (withDet)
            {
                err.Extensions["Details"] = exc.ToText();
            }
            requestContext.AddError(err, exc);
            return(err);
        }
        public static void AddError(this FieldContext fieldContext, Exception exc, string errorType)
        {
            var reqCtx  = (RequestContext)fieldContext.RequestContext;
            var path    = fieldContext.GetFullRequestPath();
            var err     = new GraphQLError(exc.Message, path, fieldContext.SelectionField.SourceLocation, type: errorType);
            var withDet = reqCtx.Server.Settings.Options.IsSet(GraphQLServerOptions.ReturnExceptionDetails);

            if (withDet)
            {
                err.Extensions["Details"] = exc.ToText();
            }
            reqCtx.AddError(err, exc);
        }
        public void InEquality2Fact()
        {
            var graphQLError1 = new GraphQLError("message")
            {
                Locations = new[] { new GraphQLLocation {
                                        Column = 1, Line = 2
                                    } }
            };
            var graphQLError2 = new GraphQLError("message")
            {
                Locations = new[] { new GraphQLLocation {
                                        Column = 2, Line = 1
                                    } }
            };

            Assert.NotEqual(graphQLError1, graphQLError2);
        }
        public void GetHashCodeFact()
        {
            var graphQLError1 = new GraphQLError("message")
            {
                Locations = new[] { new GraphQLLocation {
                                        Column = 1, Line = 2
                                    } }
            };
            var graphQLError2 = new GraphQLError("message")
            {
                Locations = new[] { new GraphQLLocation {
                                        Column = 1, Line = 2
                                    } }
            };

            Assert.True(graphQLError1.GetHashCode() == graphQLError2.GetHashCode());
        }
Example #22
0
        public void ThrowExceptionIfGraphQLErrorResponseHasError_whenErrorClassIsUnsupportedClient_throwsUnsupportedClientException()
        {
            Dictionary <string, string> extensions = new Dictionary <string, string>();

            extensions.Add("errorClass", "UNSUPPORTED_CLIENT");

            GraphQLError error = new GraphQLError();

            error.extensions = extensions;

            GraphQLResponse response = new GraphQLResponse();

            response.errors = new List <GraphQLError>();
            response.errors.Add(error);

            Assert.Throws <UpgradeRequiredException> (() => BraintreeGraphQLService.ThrowExceptionIfGraphQLErrorResponseHasError(response));
        }
Example #23
0
        public void ThrowExceptionIfGraphQLErrorResponseHasError_whenErrorClassIsNotFound_throwsNotFoundException()
        {
            Dictionary <string, string> extensions = new Dictionary <string, string>();

            extensions.Add("errorClass", "NOT_FOUND");

            GraphQLError error = new GraphQLError();

            error.extensions = extensions;

            GraphQLResponse response = new GraphQLResponse();

            response.errors = new List <GraphQLError>();
            response.errors.Add(error);

            Assert.Throws <NotFoundException> (() => BraintreeGraphQLService.ThrowExceptionIfGraphQLErrorResponseHasError(response));
        }
Example #24
0
        public void ThrowExceptionIfGraphQLErrorResponseHasError_whenErrorClassIsAuthorization_throwsAuthorizationException()
        {
            Dictionary <string, string> extensions = new Dictionary <string, string>();

            extensions.Add("errorClass", "AUTHORIZATION");

            GraphQLError error = new GraphQLError();

            error.extensions = extensions;

            GraphQLResponse response = new GraphQLResponse();

            response.errors = new List <GraphQLError>();
            response.errors.Add(error);

            Assert.Throws <AuthorizationException> (() => BraintreeGraphQLService.ThrowExceptionIfGraphQLErrorResponseHasError(response));
        }
Example #25
0
        public void ThrowExceptionIfGraphQLErrorResponseHasError_whenErrorClassIsUnknown_throwsUnexpectedException()
        {
            Dictionary <string, string> extensions = new Dictionary <string, string>();

            extensions.Add("errorClass", "UNKNOWN");

            GraphQLError error = new GraphQLError();

            error.extensions = extensions;

            GraphQLResponse response = new GraphQLResponse();

            response.errors = new List <GraphQLError>();
            response.errors.Add(error);

            Assert.Throws <UnexpectedException> (() => BraintreeGraphQLService.ThrowExceptionIfGraphQLErrorResponseHasError(response));
        }
Example #26
0
        public void ThrowExceptionIfGraphQLErrorResponseHasError_whenErrorClassIsBraintreeServiceAvailability_throwsDownForMaintanceException()
        {
            Dictionary <string, string> extensions = new Dictionary <string, string>();

            extensions.Add("errorClass", "SERVICE_AVAILABILITY");

            GraphQLError error = new GraphQLError();

            error.extensions = extensions;

            GraphQLResponse response = new GraphQLResponse();

            response.errors = new List <GraphQLError>();
            response.errors.Add(error);

            Assert.Throws <DownForMaintenanceException> (() => BraintreeGraphQLService.ThrowExceptionIfGraphQLErrorResponseHasError(response));
        }
        public void EqualityOperatorFact()
        {
            var graphQLError1 = new GraphQLError("message")
            {
                Locations = new[] { new GraphQLLocation {
                                        Column = 1, Line = 2
                                    } }
            };
            var graphQLError2 = new GraphQLError("message")
            {
                Locations = new[] { new GraphQLLocation {
                                        Column = 1, Line = 2
                                    } }
            };

            Assert.True(graphQLError1 == graphQLError2);
        }
Example #28
0
        public void ThrowExceptionIfGraphQLErrorResponseHasError_whenErrorClassIsResourceLimit_throwsTooManyRequestsException()
        {
            Dictionary <string, string> extensions = new Dictionary <string, string>();

            extensions.Add("errorClass", "RESOURCE_LIMIT");

            GraphQLError error = new GraphQLError();

            error.extensions = extensions;

            GraphQLResponse response = new GraphQLResponse();

            response.errors = new List <GraphQLError>();
            response.errors.Add(error);

            Assert.Throws <TooManyRequestsException> (() => BraintreeGraphQLService.ThrowExceptionIfGraphQLErrorResponseHasError(response));
        }
Example #29
0
        public void DoNotThrowExceptionIfGraphQLErrorResponseHasError_whenErrorClassIsValidation()
        {
            Dictionary <string, string> extensions = new Dictionary <string, string>();

            extensions.Add("errorClass", "VALIDATION");

            GraphQLError error = new GraphQLError();

            error.extensions = extensions;

            GraphQLResponse response = new GraphQLResponse();

            response.errors = new List <GraphQLError>();
            response.errors.Add(error);

            BraintreeGraphQLService.ThrowExceptionIfGraphQLErrorResponseHasError(response);
        }
Example #30
0
        public void ThrowExceptionIfGraphQLErrorResponseHasError_whenErrorClassIsInternal_throwsServerException()
        {
            Dictionary <string, string> extensions = new Dictionary <string, string>();

            extensions.Add("errorClass", "INTERNAL");

            GraphQLError error = new GraphQLError();

            error.extensions = extensions;

            GraphQLResponse response = new GraphQLResponse();

            response.errors = new List <GraphQLError>();
            response.errors.Add(error);

            Assert.Throws <ServerException> (() => BraintreeGraphQLService.ThrowExceptionIfGraphQLErrorResponseHasError(response));
        }