Skip to content

Commit

Permalink
Merge pull request #33 from tm-kn/32-add-page-path-to-api
Browse files Browse the repository at this point in the history
Display path in the API
  • Loading branch information
tm-kn committed Apr 18, 2019
2 parents e145573 + abf840c commit 6744201
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions wagtail_graphql/types/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class PageInterface(graphene.Interface):
Set basic fields exposed on every single page object.
"""
id = graphene.Int()
url = graphene.String()
depth = graphene.Int()
page_type = graphene.String()
title = graphene.String()
Expand All @@ -44,6 +45,12 @@ class Meta:
'Interface used by every GraphQL Wagtail page object type.'
)

def resolve_url(self, info):
request = info.context
return self.get_url(
request=request, current_site=request.site
)

def resolve_page_type(self, info):
return '.'.join(
[
Expand Down
3 changes: 3 additions & 0 deletions wagtail_graphql/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ def get_base_queryset_for_page_model_or_qs(page_model_or_qs, info, **kwargs):
request = info.context
page_qs = model_to_qs(page_model_or_qs)

# Only display pages for the current request's site.
page_qs = page_qs.in_site(request.site)

page_qs = exclude_invisible_pages(request, page_qs)
page_qs = page_qs.select_related('content_type')
return resolve_queryset(page_qs, info, **kwargs)

0 comments on commit 6744201

Please sign in to comment.