diff --git a/grapple/types/documents.py b/grapple/types/documents.py index df74625d..00b94556 100644 --- a/grapple/types/documents.py +++ b/grapple/types/documents.py @@ -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) diff --git a/grapple/types/images.py b/grapple/types/images.py index 1314dec6..ee282ce5 100644 --- a/grapple/types/images.py +++ b/grapple/types/images.py @@ -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)