本文整理汇总了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
}
示例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)
示例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
示例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)
示例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
示例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
示例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
示例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
示例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
示例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)
示例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
示例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