@@ 25,6 25,19 @@ func Errorf(code ErrorCode, format string, a ...any) *gqlerror.Error {
}
}
+// Creates a new "redirect" GraphQL error pointing to the provided path. The
+// path should be broken down into path segments. The length of the path is
+// dependent on the type of resource being requested.
+func RedirectTo(path []string) *gqlerror.Error {
+ return &gqlerror.Error{
+ Message: "The requested resource was moved",
+ Extensions: map[string]any{
+ "code": Redirect,
+ "redirect": path,
+ },
+ }
+}
+
// Sets the field name that caused the error
func Field(err *gqlerror.Error, field string) *gqlerror.Error {
err.Extensions["field"] = field
@@ 57,6 70,7 @@ var (
Unauthorized ErrorCode = "ERR_UNAUTHORIZED"
InternalError ErrorCode = "ERR_INTERNAL"
Timeout ErrorCode = "ERR_TIMEOUT"
+ Redirect ErrorCode = "ERR_REDIRECT"
)
// Error codes as Go errors
@@ 67,4 81,5 @@ var (
ErrUnauthorized = New(Unauthorized, "Unauthorized")
ErrInternalError = New(InternalError, "Internal server error")
ErrTimeout = New(Timeout, "Operation timed out")
+ ErrRedirect = New(Redirect, "The requested resource was moved")
)