Skip to content

RetrieveField for detail entity #4

Description

@Luferov

Very often it happens that you need to get one entity from the database by some key.
For example:

import graphene


class Query(graphene.ObjectType):
    object = graphene.Field(ObjectType, object_id=graphene.Int(required=True), description)

    @staticmethod
    def resolve_object(root: Any, info: ResolveInfo, object_id: int):
         return get_object_or_404(Object, pk=object_id)

Replaced by:

from typing import Optional
import graphene

class Query(graphene.ObjectType):
    object = RetrieveField(ObjectType, key: Optional[str]='object_id', description: Optional[str] = 'Description')

object may be user, group, etc. key and description may generate automatically or set by user.
Clarification about key: UserType -> key = user_id, GroupType -> key = group_id, etc.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions