简体   繁体   English

没有模型绑定的Graphene / GraphQL查询

[英]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. 我想从客户端传递JSON,在服务器端处理该JSON,然后根据JSON内容响应客户端。

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. 我知道,在Python / Django的通常情况下,我需要使用Graphene / GraphQL,在其中我需要用降落伞的Meta类绑定的模型来描述DjangoObjectType降落伞。 Then I should include this class to Query class, as class field. 然后,我应该将该类包括在Query类中,作为类字段。

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? 我不需要查询的任何模型绑定,如何解决我的任务?

I've finally found solution: 我终于找到了解决方案:

For example, as was stated in the question, you need to pass some json to server. 例如,如问题中所述,您需要将一些json传递到服务器。

On your Python backend you need to define following Query class: 在您的Python后端上,您需要定义以下Query类:

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: 在GraphQL客户端,您需要定义以下查询语句:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM