MStikh
MStikh

Reputation: 404

How to allow any field filtering in graphene GraphQl

I was wondering, if there is a way to pass more arguments to be queried in the graphene GraphQl resolver.

So this code works for wgr_bez only:

class GraphqlService(graphene.ObjectType):
    get_single_article = graphene.Field(ArticleGrapheneModel, wgr_bez=graphene.String)


    @staticmethod
    async def resolve_get_single_article(parent, info, **kwargs):
        article = await info.context['request'].state.db.select_article_with_filter(kwargs)
        return article[0][0].to_json()

With **kwargs I can get any column:value pair from the request, but how to pass any column:value, I do not understand.

I want to be able to replace it with something more general or at least a dictionary. I saw it in the documentation, but when I do I get an error:

get_single_article = graphene.Field(ArticleGrapheneModel, {'wgr_bez': graphene.String, 'id': graphene.Int})

ValueError: Unknown argument "wgr_bez".

Upvotes: 0

Views: 195

Answers (1)

MStikh
MStikh

Reputation: 404

I found an answer, one needs to define argumets as follows:

get_single_article = graphene.Field(ArticleGrapheneModel, args={'wgr_bez': graphene.Argument(graphene.String),
                                                                'id': graphene.Argument(graphene.Int)})

Upvotes: 0

Related Questions