From 923e5e9e411b29d4d4997135c64f6715c140f843 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Fri, 13 Sep 2024 15:07:45 -0400 Subject: [PATCH] refactor: GQL responses need to include the path prefix, too --- src/gql/resolvers/RetourResolver.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/gql/resolvers/RetourResolver.php b/src/gql/resolvers/RetourResolver.php index 6b960cef..14cc0173 100644 --- a/src/gql/resolvers/RetourResolver.php +++ b/src/gql/resolvers/RetourResolver.php @@ -13,9 +13,10 @@ use Craft; use craft\base\Element; +use craft\errors\SiteNotFoundException; use craft\gql\base\Resolver; -use craft\helpers\UrlHelper; use GraphQL\Type\Definition\ResolveInfo; +use nystudio107\retour\helpers\UrlHelper; use nystudio107\retour\Retour; /** @@ -74,6 +75,17 @@ public static function resolve(mixed $source, array $arguments, mixed $context, Retour::$plugin->statistics->incrementStatistics($uri, false, $siteId); } } + $dest = $redirect['redirectDestUrl']; + // If this isn't an absolute URL, make it one based on the appropriate site + if (!UrlHelper::isAbsoluteUrl($dest)) { + try { + $dest = UrlHelper::siteUrl($dest, null, null, $siteId); + $dest = parse_url($dest, PHP_URL_PATH); + } catch (Throwable $e) { + // That's ok + } + } + $redirect['redirectDestUrl'] = $dest; return $redirect; } @@ -86,7 +98,7 @@ public static function resolve(mixed $source, array $arguments, mixed $context, * @param $context * @param ResolveInfo $resolveInfo * @return array - * @throws \craft\errors\SiteNotFoundException + * @throws SiteNotFoundException */ public static function resolveAll($source, array $arguments, $context, ResolveInfo $resolveInfo) {