Skip to content

Commit 56f0f31

Browse files
TheBnljasonvarga
andauthored
[5.x] Only apply the published filter when not in preview mode (#11652)
Co-authored-by: Jason Varga <[email protected]>
1 parent 139c120 commit 56f0f31

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/GraphQL/Queries/EntryQuery.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function resolve($root, $args)
6969
$query->where('site', $site);
7070
}
7171

72-
$filters = $args['filter'] ?? null;
72+
$filters = $args['filter'] ?? [];
7373

7474
$this->filterQuery($query, $filters);
7575

@@ -107,7 +107,7 @@ public function resolve($root, $args)
107107

108108
private function filterQuery($query, $filters)
109109
{
110-
if (! isset($filters['status']) && ! isset($filters['published'])) {
110+
if (! request()->isLivePreview() && (! isset($filters['status']) && ! isset($filters['published']))) {
111111
$filters['status'] = 'published';
112112
}
113113

tests/Feature/GraphQL/EntryTest.php

+41
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Facades\Statamic\API\FilterAuthorizer;
66
use Facades\Statamic\API\ResourceAuthorizer;
7+
use Facades\Statamic\CP\LivePreview;
78
use Facades\Statamic\Fields\BlueprintRepository;
89
use Facades\Tests\Factories\EntryFactory;
910
use PHPUnit\Framework\Attributes\DataProvider;
@@ -755,4 +756,44 @@ public function it_only_shows_published_entries_by_default()
755756
'title' => 'That will be so rad!',
756757
]]]);
757758
}
759+
760+
#[Test]
761+
public function it_only_shows_unpublished_entries_with_token()
762+
{
763+
FilterAuthorizer::shouldReceive('allowedForSubResources')
764+
->andReturn(['published', 'status']);
765+
766+
$entry = EntryFactory::collection('blog')
767+
->id('6')
768+
->slug('that-was-so-rad')
769+
->data(['title' => 'That was so rad!'])
770+
->published(false)
771+
->create();
772+
773+
LivePreview::tokenize('test-token', $entry);
774+
775+
$query = <<<'GQL'
776+
{
777+
entry(id: "6") {
778+
id
779+
title
780+
}
781+
}
782+
GQL;
783+
784+
$this
785+
->withoutExceptionHandling()
786+
->post('/graphql', ['query' => $query])
787+
->assertGqlOk()
788+
->assertExactJson(['data' => ['entry' => null]]);
789+
790+
$this
791+
->withoutExceptionHandling()
792+
->post('/graphql?token=test-token', ['query' => $query])
793+
->assertGqlOk()
794+
->assertExactJson(['data' => ['entry' => [
795+
'id' => '6',
796+
'title' => 'That was so rad!',
797+
]]]);
798+
}
758799
}

0 commit comments

Comments
 (0)