question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to filter the child of the main query?

See original GitHub issue

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()

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
somada141commented, May 24, 2018

Hi @aleks-fr, quick q re the code you provided above. While defining the posts under User allows one to nest them the posts wont’ necessarily belong to the resolved user.

Is there a way to communicate the arguments of resolve_user to the nested resolve_posts so that posts can be limited to that user only?

0reactions
erikwredecommented, May 13, 2022

I am closing all old issues&PRs related to filtering. The discussion will continue in https://github.com/graphql-python/graphene-sqlalchemy/discussions/347 (WIP). A proposal for the implementation of filters is currently being worked on and will be posted there once it is ready.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Subquerying filtering on main query field
!= to a field of the master. Account: Master Application__c : Child. Using Subquery: select acc.id,acc.Callista_Org_Unit_Code__c , ( ...
Read more >
structure Access query to filter parent records on child record ...
I have a KitHdr table and a KitDlt table, and yes the KitDtl table is the child of the KitHdr table. There are...
Read more >
How to filter the child entity while quering the parent in hibernate
2) HQL query is. SELECT eA FROM EntityA LEFT JOIN eA.entityBList eB WHERE eA.id =:id AND eB.modelPercent > 0.
Read more >
How to Query a Parent-Child Tree in SQL | LearnSQL.com
Example 1: List All Children of 1 Parent. This is the simplest query, so I'll use it to make you more at ease...
Read more >
Query parent object by filter on the child object
List<Contact> contacts = new List<Contact>([select name from contact where id in (select contactid from campaignmember where status = 'Sent')]);.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found