当前位置: 首页>>代码示例>>Python>>正文


Python graphene.Node方法代码示例

本文整理汇总了Python中graphene.Node方法的典型用法代码示例。如果您正苦于以下问题:Python graphene.Node方法的具体用法?Python graphene.Node怎么用?Python graphene.Node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在graphene的用法示例。


在下文中一共展示了graphene.Node方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setup_fixtures

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Node [as 别名]
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
    } 
开发者ID:yfilali,项目名称:graphql-pynamodb,代码行数:25,代码来源:test_relationships.py

示例2: test_should_self_reference_convert_dynamic

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Node [as 别名]
def test_should_self_reference_convert_dynamic():
    class P(MongoengineObjectType):
        class Meta:
            model = Player
            interfaces = (graphene.Node,)

    dynamic_field = convert_mongoengine_field(
        Player._fields["opponent"], P._meta.registry
    )
    assert isinstance(dynamic_field, graphene.Dynamic)
    graphene_type = dynamic_field.get_type()
    assert isinstance(graphene_type, graphene.Field)
    assert graphene_type.type == P

    graphene_field = convert_mongoengine_field(
        Player._fields["players"], P._meta.registry
    )
    assert isinstance(graphene_field, MongoengineConnectionField) 
开发者ID:graphql-python,项目名称:graphene-mongo,代码行数:20,代码来源:test_converter.py

示例3: test_should_onetoone_convert_field

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Node [as 别名]
def test_should_onetoone_convert_field():
    class A(PynamoObjectType):
        class Meta:
            model = Article
            interfaces = [relay.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 
开发者ID:yfilali,项目名称:graphql-pynamodb,代码行数:13,代码来源:test_converter.py

示例4: test_should_onetomany_convert_field

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Node [as 别名]
def test_should_onetomany_convert_field():
    class A(PynamoObjectType):
        class Meta:
            model = Article
            interfaces = (Node,)

    dynamic_field = convert_pynamo_attribute(Reporter.articles, Reporter.articles, A._meta.registry)
    assert isinstance(dynamic_field, Dynamic)
    graphene_type = dynamic_field.get_type()
    assert isinstance(graphene_type, PynamoConnectionField) 
开发者ID:yfilali,项目名称:graphql-pynamodb,代码行数:12,代码来源:test_converter.py

示例5: test_should_reference_convert_dynamic

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Node [as 别名]
def test_should_reference_convert_dynamic():
    class E(MongoengineObjectType):
        class Meta:
            model = Editor
            interfaces = (graphene.Node,)

    dynamic_field = convert_mongoengine_field(
        EmbeddedArticle._fields["editor"], E._meta.registry
    )
    assert isinstance(dynamic_field, graphene.Dynamic)
    graphene_type = dynamic_field.get_type()
    assert isinstance(graphene_type, graphene.Field)
    assert graphene_type.type == E 
开发者ID:graphql-python,项目名称:graphene-mongo,代码行数:15,代码来源:test_converter.py

示例6: test_should_lazy_reference_convert_dynamic

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Node [as 别名]
def test_should_lazy_reference_convert_dynamic():
    class P(MongoengineObjectType):
        class Meta:
            model = Publisher
            interfaces = (graphene.Node,)

    dynamic_field = convert_mongoengine_field(
        Editor._fields["company"], P._meta.registry
    )

    assert isinstance(dynamic_field, graphene.Dynamic)
    graphene_type = dynamic_field.get_type()
    assert isinstance(graphene_type, graphene.Field)
    assert graphene_type.type == P 
开发者ID:graphql-python,项目名称:graphene-mongo,代码行数:16,代码来源:test_converter.py

示例7: test_should_embedded_convert_dynamic

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Node [as 别名]
def test_should_embedded_convert_dynamic():
    class PM(MongoengineObjectType):
        class Meta:
            model = ProfessorMetadata
            interfaces = (graphene.Node,)

    dynamic_field = convert_mongoengine_field(
        ProfessorVector._fields["metadata"], PM._meta.registry
    )
    assert isinstance(dynamic_field, graphene.Dynamic)
    graphene_type = dynamic_field.get_type()
    assert isinstance(graphene_type, graphene.Field)
    assert graphene_type.type == PM 
开发者ID:graphql-python,项目名称:graphene-mongo,代码行数:15,代码来源:test_converter.py

示例8: test_should_filter_through_inheritance

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Node [as 别名]
def test_should_filter_through_inheritance(fixtures):
    class Query(graphene.ObjectType):
        node = Node.Field()
        children = MongoengineConnectionField(nodes.ChildNode)

    query = """
        query ChildrenQuery {
            children(bar: "bar") {
                edges {
                    node {
                        bar,
                        baz,
                        loc {
                             type,
                             coordinates
                        }
                    }
                }
            }
        }
    """
    expected = {
        "children": {
            "edges": [
                {
                    "node": {
                        "bar": "bar",
                        "baz": "baz",
                        "loc": {"type": "Point", "coordinates": [10.0, 20.0]},
                    }
                }
            ]
        }
    }
    schema = graphene.Schema(query=Query)
    result = schema.execute(query)
    assert not result.errors
    assert result.data == expected 
开发者ID:graphql-python,项目名称:graphene-mongo,代码行数:40,代码来源:test_relay_query.py

示例9: test_should_get_queryset_returns_dict_filters

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Node [as 别名]
def test_should_get_queryset_returns_dict_filters(fixtures):
    class Query(graphene.ObjectType):
        node = Node.Field()
        articles = MongoengineConnectionField(
            nodes.ArticleNode, get_queryset=lambda *_, **__: {"headline": "World"}
        )

    query = """
           query ArticlesQuery {
               articles {
                   edges {
                       node {
                           headline,
                           pubDate,
                           editor {
                               firstName
                           }
                       }
                   }
               }
           }
       """
    expected = {
        "articles": {
            "edges": [
                {
                    "node": {
                        "headline": "World",
                        "editor": {"firstName": "Grant"},
                        "pubDate": "2020-01-01T00:00:00",
                    }
                }
            ]
        }
    }
    schema = graphene.Schema(query=Query)
    result = schema.execute(query)
    assert not result.errors
    assert result.data == expected 
开发者ID:graphql-python,项目名称:graphene-mongo,代码行数:41,代码来源:test_relay_query.py

示例10: __init_subclass_with_meta__

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Node [as 别名]
def __init_subclass_with_meta__(cls, model=None, registry=None, skip_registry=False,
                                    only_fields=(), exclude_fields=(), connection=None,
                                    use_connection=None, interfaces=(), id=None, **options):
        assert model and isclass(model) and issubclass(model, Model), (
            'You need to pass a valid PynamoDB Model in '
            '{}.Meta, received "{}".'
        ).format(cls.__name__, model)

        if not registry:
            registry = get_global_registry()

        assert isinstance(registry, Registry), (
            'The attribute registry in {} needs to be an instance of '
            'Registry, received "{}".'
        ).format(cls.__name__, registry)

        pynamo_fields = yank_fields_from_attrs(
            construct_fields(model, registry, only_fields, exclude_fields),
            _as=Field,
        )

        if use_connection is None and interfaces:
            use_connection = any((issubclass(interface, Node) for interface in interfaces))

        if use_connection and not connection:
            # We create the connection automatically
            connection = Connection.create_type('{}Connection'.format(cls.__name__), node=cls)

        if connection is not None:
            assert issubclass(connection, Connection), (
                "The connection must be a Connection. Received {}"
            ).format(connection.__name__)

        _meta = PynamoObjectTypeOptions(cls)
        _meta.model = model
        _meta.registry = registry
        _meta.fields = pynamo_fields
        _meta.connection = connection
        _meta.id = id or 'id'

        super(PynamoObjectType, cls).__init_subclass_with_meta__(_meta=_meta, interfaces=interfaces, **options)

        if not skip_registry:
            registry.register(cls) 
开发者ID:yfilali,项目名称:graphql-pynamodb,代码行数:46,代码来源:types.py

示例11: test_should_lazy_reference

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Node [as 别名]
def test_should_lazy_reference(fixtures):
    class Query(graphene.ObjectType):
        node = Node.Field()
        parents = MongoengineConnectionField(nodes.ParentWithRelationshipNode)

    schema = graphene.Schema(query=Query)

    query = """
    query {
        parents {
            edges {
                node {
                    beforeChild {
                        edges {
                            node {
                                name,
                                parent { name }
                            }
                        }
                    },
                    afterChild {
                        edges {
                            node {
                                name,
                                parent { name }
                            }
                        }
                    }
                }
            }
        }
    }
    """

    expected = {
        "parents": {
            "edges": [
                {
                    "node": {
                        "beforeChild": {
                            "edges": [
                                {"node": {"name": "Akari", "parent": {"name": "Yui"}}}
                            ]
                        },
                        "afterChild": {
                            "edges": [
                                {"node": {"name": "Kyouko", "parent": {"name": "Yui"}}}
                            ]
                        },
                    }
                }
            ]
        }
    }

    result = schema.execute(query)
    assert not result.errors
    assert result.data == expected 
开发者ID:graphql-python,项目名称:graphene-mongo,代码行数:60,代码来源:test_relay_query.py

示例12: test_should_get_queryset_returns_qs_filters

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import Node [as 别名]
def test_should_get_queryset_returns_qs_filters(fixtures):
    def get_queryset(model, info, **args):
        return model.objects(headline="World")

    class Query(graphene.ObjectType):
        node = Node.Field()
        articles = MongoengineConnectionField(
            nodes.ArticleNode, get_queryset=get_queryset
        )

    query = """
           query ArticlesQuery {
               articles {
                   edges {
                       node {
                           headline,
                           pubDate,
                           editor {
                               firstName
                           }
                       }
                   }
               }
           }
       """
    expected = {
        "articles": {
            "edges": [
                {
                    "node": {
                        "headline": "World",
                        "editor": {"firstName": "Grant"},
                        "pubDate": "2020-01-01T00:00:00",
                    }
                }
            ]
        }
    }
    schema = graphene.Schema(query=Query)
    result = schema.execute(query)
    assert not result.errors
    assert result.data == expected 
开发者ID:graphql-python,项目名称:graphene-mongo,代码行数:44,代码来源:test_relay_query.py


注:本文中的graphene.Node方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。