Skip to content

How to filter the child of the main query? #110

Closed
@afr-dt

Description

@afr-dt

I'm a relative newcomer to Graphene, I'm trying to make a query like this
Query example

{
   user(username: "Jon") { 
     name
     last_lame
     username
     posts(in_draft : true) { 
       title
       text
       in_draft
       update_at      
     }
   }
}

Filter the posts that are in draft. Is this possible?

Query:

class Query(graphene.ObjectType):

    user = graphene.Field(lambda: User, username=graphene.String())
    def resolve_user(self, info, username):
       query = User.get_query(info)
       return query.filter(UserModel.username == username).first()


   posts = graphene.List(lambda: Post, in_draft=graphene.Boolean())
   def resolve_posts(self, info, in_draft):
      query = Post.get_query(info)
      return query.filter(PostModel.in_draft == in_draft).all()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions