Skip to content

Commit

Permalink
feat: add singular queries for images and documents
Browse files Browse the repository at this point in the history
  • Loading branch information
ruisaraiva19 committed Oct 9, 2020
1 parent 8a04215 commit 76d0f95
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion grapple/types/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,20 @@ def DocumentsQuery():
model_type = registry.documents[mdl]

class Mixin:
document = graphene.Field(model_type, id=graphene.ID())
documents = QuerySetList(
graphene.NonNull(model_type), enable_search=True, required=True
)

# Return all pages, ideally specific.
# Return one document.
def resolve_document(self, info, **kwargs):
id = kwargs.get("id")
try:
return mdl.objects.get(pk=id)
except BaseException:
return None

# Return all documents.
def resolve_documents(self, info, **kwargs):
return resolve_queryset(mdl.objects.all(), info, **kwargs)

Expand Down
11 changes: 10 additions & 1 deletion grapple/types/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,21 @@ def ImagesQuery():
mdl_type = get_image_type()

class Mixin:
image = graphene.Field(mdl_type, id=graphene.ID())
images = QuerySetList(
graphene.NonNull(mdl_type), enable_search=True, required=True
)
image_type = graphene.String(required=True)

# Return all pages, ideally specific.
# Return one image.
def resolve_image(self, info, **kwargs):
id = kwargs.get("id")
try:
return mdl.objects.get(pk=id)
except BaseException:
return None

# Return all images.
def resolve_images(self, info, **kwargs):
return resolve_queryset(mdl.objects.all(), info, **kwargs)

Expand Down

0 comments on commit 76d0f95

Please sign in to comment.