微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python graphene 模块-Node() 实例源码

Python graphene 模块,Node() 实例源码

我们从Python开源项目中,提取了以下3代码示例,用于说明如何使用graphene.Node()

项目:graphql-pynamodb    作者:yfilali    | 项目源码 | 文件源码
def setup_fixtures():
    class ReporterType(PynamoObjectType):
        class Meta:
            model = Reporter
            interfaces = (Node,)

    class ArticleType(PynamoObjectType):
        class Meta:
            model = Article
            interfaces = (Node,)

    reporter1 = Reporter(1, first_name="John", last_name="SNow")
    article1 = Article(1, headline="Hi!", reporter=reporter1)
    article2 = Article(2, headline="Lame Article", reporter=reporter1)
    reporter1.articles = [article1, article2]

    return {
        'ReporterType': ReporterType,
        'ArticleType': ArticleType,
        'reporter1': reporter1,
        'article1': article1,
        'article2': article2
    }
项目:graphql-pynamodb    作者:yfilali    | 项目源码 | 文件源码
def test_should_onetoone_convert_field():
    class A(PynamoObjectType):
        class Meta:
            model = Article
            interfaces = (Node,)

    dynamic_field = convert_pynamo_attribute(Reporter.favorite_article, Reporter.favorite_article, A._Meta.registry)
    assert isinstance(dynamic_field, Dynamic)
    graphene_type = dynamic_field.get_type()
    assert isinstance(graphene_type, graphene.Field)
    assert graphene_type.type == A
项目:graphql-pynamodb    作者:yfilali    | 项目源码 | 文件源码
def test_should_onetomany_convert_field():
    class A(PynamoObjectType):
        class Meta:
            model = Article
            interfaces = (Node,)

    dynamic_field = convert_pynamo_attribute(Reporter.articles, Reporter.articles, PynamoConnectionField)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐