Closed jmartinhoj closed 1 year ago
Field users
of UserResults
has its own resolver (provided by SQLAlchemyConnectionField(User.connection)
).
When your resolve_all_users
resolver returns the filtered query result, it is passed as a parent to UserResults
. Then,UserResults
runs the field resolver for users
, which is specified in the SQLAlchemyConnectionField
. Since the list of filtered user is the parent value of this field, not the field's value itself, this resolver queries the database again. Now, you get the full list of users.
The simplest fix would be to create a custom resolver:
class UserResults(graphene.ObjectType):
users = SQLAlchemyConnectionField(User.connection)
def resolve_users(parent, info): # parent is of type list because it was returned by `resolve_all_users`
return parent
Hope that helps!
That's it! Thank you!
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related topics referencing this issue.
I need a query to return either a list of SQLAlchemy objects (via a connection) or an error message. Here's the code:
When the
''''condition'''
is met and a Message is returned, it works well. Unfortunately, otherwise, when a list of Users is returned, the list of users that is returned in graphql is the complete list of all users, no matter the filter in the query. Is this a bug or should I do it differently?