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();
        }
        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();
        }
Beispiel #3
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 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);
        }