-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #824 from Inter-Actief/822-add-the-about-module-to…
…-the-graphql-api Add about pages to the GraphQL API
- Loading branch information
Showing
4 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from django.db.models import Q | ||
from django.utils.translation import gettext_lazy as _ | ||
import graphene | ||
from graphene_django import DjangoObjectType | ||
|
||
from amelie.about.models import Page | ||
from amelie.graphql.pagination.connection_field import DjangoPaginationConnectionField | ||
|
||
|
||
class PageType(DjangoObjectType): | ||
class Meta: | ||
model = Page | ||
description = "Type definition for a single Page" | ||
fields = ["name_nl", "name_en", "slug_nl", "slug_en", "educational", "content_nl", "content_en", "last_modified"] | ||
|
||
name = graphene.String(description=_("Page name")) | ||
slug = graphene.String(description=_("Page slug")) | ||
content = graphene.String(description=_("Page content")) | ||
|
||
def resolve_name(obj: Page, info): | ||
return obj.name | ||
|
||
def resolve_slug(obj: Page, info): | ||
return obj.slug | ||
|
||
def resolve_content(obj: Page, info): | ||
return obj.content | ||
|
||
|
||
class AboutQuery(graphene.ObjectType): | ||
page = graphene.Field(PageType, id=graphene.ID(), slug=graphene.String()) | ||
|
||
def resolve_page(self, info, id=None, slug=None): | ||
if id is not None: | ||
return Page.objects.get(pk=id) | ||
if slug is not None: | ||
return Page.objects.get(Q(slug_en=slug) | Q(slug_nl=slug)) | ||
return None | ||
|
||
|
||
# Exports | ||
GRAPHQL_QUERIES = [AboutQuery] | ||
GRAPHQL_MUTATIONS = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters