From cf3bd44577eaf0aa4f347248d819d22a36f0d7ab Mon Sep 17 00:00:00 2001 From: Patrick Stillhart Date: Tue, 21 May 2024 13:30:29 +0200 Subject: [PATCH 1/2] feat: add site filter to TermsQuery --- src/GraphQL/Queries/TermsQuery.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/GraphQL/Queries/TermsQuery.php b/src/GraphQL/Queries/TermsQuery.php index 8becd6a1c1..7fb3ae0f70 100644 --- a/src/GraphQL/Queries/TermsQuery.php +++ b/src/GraphQL/Queries/TermsQuery.php @@ -42,6 +42,7 @@ public function args(): array 'page' => GraphQL::int(), 'filter' => GraphQL::type(JsonArgument::NAME), 'sort' => GraphQL::listOf(GraphQL::string()), + 'site' => GraphQL::string(), ]; } @@ -59,6 +60,10 @@ public function resolve($root, $args) $this->sortQuery($query, $sort); } + if ($site = $args['site'] ?? null) { + $query->where('site', $site); + } + return $query->paginate($args['limit'] ?? 1000); } From bd40b9c8b8fb561faeef2b3e656c7af185ffcc67 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Tue, 28 May 2024 10:40:39 -0400 Subject: [PATCH 2/2] add test --- tests/Feature/GraphQL/TermsTest.php | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/Feature/GraphQL/TermsTest.php b/tests/Feature/GraphQL/TermsTest.php index 5e334f14b6..87786b486c 100644 --- a/tests/Feature/GraphQL/TermsTest.php +++ b/tests/Feature/GraphQL/TermsTest.php @@ -105,6 +105,40 @@ public function it_queries_all_terms() ]]]]); } + /** @test */ + public function it_queries_all_terms_in_a_specific_site() + { + $this->createTaxonomies()->createTerms()->createBlueprints(); + + $this->setSites([ + 'en' => ['url' => 'http://localhost/', 'locale' => 'en'], + 'fr' => ['url' => 'http://localhost/fr/', 'locale' => 'fr'], + ]); + + Taxonomy::find('tags')->sites(['en', 'fr'])->save(); + + Term::find('tags::alpha')->in('fr')->data(['title' => 'Le Alpha'])->save(); + + $query = <<<'GQL' +{ + terms(site: "fr") { + data { + id + title + } + } +} +GQL; + + $this + ->withoutExceptionHandling() + ->post('/graphql', ['query' => $query]) + ->assertGqlOk() + ->assertExactJson(['data' => ['terms' => ['data' => [ + ['id' => 'tags::alpha', 'title' => 'Le Alpha'], + ]]]]); + } + /** @test */ public function it_queries_only_terms_on_allowed_sub_resources() {