Skip to content

Commit

Permalink
Enable query_params on plural queries torchbox#219
Browse files Browse the repository at this point in the history
  • Loading branch information
flyte committed Apr 9, 2022
1 parent 9b8a49c commit 4ab19b4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
16 changes: 16 additions & 0 deletions example/home/test/test_advert.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ def test_advert_all_query(self):
# Check all the fields
self.validate_advert(advert)

def test_advert_all_query_fields(self):
query = """
query($url: String) {
adverts(url: $url) {
id
url
text
}
}
"""
executed = self.client.execute(query, variables={"url": self.advert.url})
advert = executed["data"]["adverts"][0]

# Check all the fields
self.validate_advert(advert)

def test_advert_single_query(self):
query = """
query($url: String) {
Expand Down
4 changes: 3 additions & 1 deletion grapple/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ def resolve_plural(self, _, info, **kwargs):
setattr(
schema,
plural_field_name,
QuerySetList(plural_field_type, required=plural_required),
QuerySetList(
plural_field_type, required=plural_required, **field_query_params
),
)

setattr(
Expand Down
4 changes: 2 additions & 2 deletions grapple/types/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,12 @@ class Mixin:
)

# Return all pages in site, ideally specific.
def resolve_pages(self, info, **kwargs):
def resolve_pages(self, info, in_site=False, **kwargs):
pages = (
WagtailPage.objects.live().public().filter(depth__gt=1).specific()
) # no need to the root page

if kwargs.get("in_site", False):
if in_site:
site = Site.find_for_request(info.context)
pages = pages.in_site(site)

Expand Down
4 changes: 2 additions & 2 deletions grapple/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ def resolve_queryset(
:type collection: int
"""

if kwargs:
qs = qs.filter(**kwargs)
if id is not None:
qs = qs.filter(pk=id)
else:
qs = qs.all()

if id is None and search_query:
# Check if the queryset is searchable using Wagtail search.
Expand Down

0 comments on commit 4ab19b4

Please sign in to comment.