diff --git a/src/GraphQL/Resolvers/VersionFilters.php b/src/GraphQL/Resolvers/VersionFilters.php index 9e134e04..17be36e7 100644 --- a/src/GraphQL/Resolvers/VersionFilters.php +++ b/src/GraphQL/Resolvers/VersionFilters.php @@ -32,9 +32,11 @@ public function applyToReadingState(array $versioningArgs) switch ($mode) { case Versioned::LIVE: case Versioned::DRAFT: + Versioned::set_stage($mode); + break; case 'latest_versions': case 'all_versions': - Versioned::set_stage($mode); + Versioned::set_reading_mode($mode); break; case 'archive': $date = $versioningArgs['archiveDate']; @@ -186,6 +188,8 @@ public function validateArgs(array $versioningArgs) switch ($mode) { case Versioned::LIVE: case Versioned::DRAFT: + case 'all_versions': + case 'latest_versions': break; case 'archive': if (empty($versioningArgs['archiveDate'])) { @@ -202,10 +206,6 @@ public function validateArgs(array $versioningArgs) )); } break; - case 'all_versions': - break; - case 'latest_versions': - break; case 'status': if (empty($versioningArgs['status'])) { throw new InvalidArgumentException(sprintf( diff --git a/src/GraphQL/Resolvers/VersionedResolver.php b/src/GraphQL/Resolvers/VersionedResolver.php index 9ff0b6f4..37e04dfb 100644 --- a/src/GraphQL/Resolvers/VersionedResolver.php +++ b/src/GraphQL/Resolvers/VersionedResolver.php @@ -5,7 +5,6 @@ use GraphQL\Type\Definition\ResolveInfo; use SilverStripe\Core\Injector\Injector; -use SilverStripe\GraphQL\QueryHandler\QueryHandler; use SilverStripe\GraphQL\QueryHandler\UserContextProvider; use SilverStripe\GraphQL\Resolvers\VersionFilters; use SilverStripe\ORM\DataList; @@ -101,11 +100,18 @@ public static function resolveVersionedRead(DataList $list, array $args, array $ return $list; } - // Set the reading state globally, we don't support mixing versioned states in the same query - Injector::inst()->get(VersionFilters::class) - ->applyToReadingState($args['versioning']); + // Set the reading state globally, we don't support mixing versioned + // states in the same query + try { + Injector::inst()->get(VersionFilters::class) + ->applyToReadingState($args['versioning']); + } catch (InvalidArgumentException $e) { + // We don't really care if the args don't apply to the global state, + // because if they don't work there, they'll work on the list in the next, + // call, unless it's something totally unexpected, which will throw. + } - // Also set on the specific list + // Set on the specific list $list = Injector::inst()->get(VersionFilters::class) ->applyToList($list, $args['versioning']);