AlGiorgio
AlGiorgio

Reputation: 497

Graphene/GraphQL query without model binding

I want to pass JSON from client-side, process that JSON on server-side and then response to Client depending on JSON content.

I know, that in usual case with Python/Django I need to use Graphene/GraphQL where I need to describe DjangoObjectType descendant with model, binded in descendat's Meta class. Then I should include this class to Query class, as class field.

This is the way of models' data communication via Graphene.

How can I solve my task as I don't need any model binding for my Query?

Upvotes: 4

Views: 1833

Answers (1)

AlGiorgio
AlGiorgio

Reputation: 497

I've finally found solution:

For example, as was stated in the question, you need to pass some json to server.

On your Python backend you need to define following Query class:

class Query(graphene.ObjectType):

    searcher = graphene.JSONString(name=graphene.JSONString(default_value='{"first": 100}'))

    def resolve_searcher(self, type, passed_json):
        some_result = do_some_with_json(passed_json)
        return some_result

On your GraphQL Client side you need to define following query statement:

query {
    searcher(name: "{\"first\": 1000}")
}

Upvotes: 6

Related Questions