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); } 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() {