4.Schema架构

The graphene.Schema object describes your data model and provides a GraphQL server with an associated set of resolve methods that know how to fetch data. The most basic schema you can create looks like this:

graphene.Schema对象描述您的数据模型,并为GraphQL服务器提供一组相关联的解析方法,这些方法知道如何获取数据。您可以创建的最基本架构如下所示:

import graphene

class Query(graphene.ObjectType):
    pass

class Mutation(graphene.ObjectType):
    pass

schema = graphene.Schema(query=Query, mutation=Mutation)

This schema doesn’t do anything yet, but it is ready to accept new Query or Mutation fields.

这个模式还没有做任何事情,但它已经准备好接受新的查询或变异字段。

Adding to the schema 添加到架构

If you have defined a Query or Mutation, you can register them with the schema:

如果定义了Query“查询”或Mutation“变异”,则可以将它们注册到架构中:

import graphene

import my_app.schema.Query
import my_app.schema.Mutation

class Query(
    my_app.schema.Query, # Add your Query objects here
    graphene.ObjectType
):
    pass

class Mutation(
    my_app.schema.Mutation, # Add your Mutation objects here
    graphene.ObjectType
):
    pass

schema = graphene.Schema(query=Query, mutation=Mutation)

You can add as many mixins to the base Query and Mutation objects as you like.

您可以在基本“查询”和“突变”对象中添加任意数量的mixin。

Read more about Schema on the core graphene docs

阅读核心石墨烯文档了解更多关于图式的内容

posted @ 2020-09-25 07:07  双葫  阅读(99)  评论(0编辑  收藏  举报