本文整理汇总了Python中graphene.relay.ConnectionField方法的典型用法代码示例。如果您正苦于以下问题:Python relay.ConnectionField方法的具体用法?Python relay.ConnectionField怎么用?Python relay.ConnectionField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphene.relay
的用法示例。
在下文中一共展示了relay.ConnectionField方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: type
# 需要导入模块: from graphene import relay [as 别名]
# 或者: from graphene.relay import ConnectionField [as 别名]
def type(self):
from .types import SQLAlchemyObjectType
_type = super(ConnectionField, self).type
nullable_type = get_nullable_type(_type)
if issubclass(nullable_type, Connection):
return _type
assert issubclass(nullable_type, SQLAlchemyObjectType), (
"SQLALchemyConnectionField only accepts SQLAlchemyObjectType types, not {}"
).format(nullable_type.__name__)
assert (
nullable_type.connection
), "The type {} doesn't have a connection".format(
nullable_type.__name__
)
assert _type == nullable_type, (
"Passing a SQLAlchemyObjectType instance is deprecated. "
"Pass the connection type instead accessible via SQLAlchemyObjectType.connection"
)
return nullable_type.connection
示例2: type
# 需要导入模块: from graphene import relay [as 别名]
# 或者: from graphene.relay import ConnectionField [as 别名]
def type(self):
from .types import DjangoObjectType
_type = super(ConnectionField, self).type
non_null = False
if isinstance(_type, NonNull):
_type = _type.of_type
non_null = True
assert issubclass(
_type, DjangoObjectType
), "DjangoConnectionField only accepts DjangoObjectType types"
assert _type._meta.connection, "The type {} doesn't have a connection".format(
_type.__name__
)
connection_type = _type._meta.connection
if non_null:
return NonNull(connection_type)
return connection_type
示例3: test_issue
# 需要导入模块: from graphene import relay [as 别名]
# 或者: from graphene.relay import ConnectionField [as 别名]
def test_issue():
class Query(graphene.ObjectType):
things = relay.ConnectionField(MyUnion)
with raises(Exception) as exc_info:
graphene.Schema(query=Query)
assert str(exc_info.value) == (
"Query fields cannot be resolved."
" IterableConnectionField type has to be a subclass of Connection."
' Received "MyUnion".'
)
示例4: type
# 需要导入模块: from graphene import relay [as 别名]
# 或者: from graphene.relay import ConnectionField [as 别名]
def type(self):
from .types import MongoengineObjectType
_type = super(ConnectionField, self).type
assert issubclass(
_type, MongoengineObjectType
), "MongoengineConnectionField only accepts MongoengineObjectType types"
assert _type._meta.connection, "The type {} doesn't have a connection".format(
_type.__name__
)
return _type._meta.connection
示例5: test_should_manytomany_convert_connectionorlist_connection
# 需要导入模块: from graphene import relay [as 别名]
# 或者: from graphene.relay import ConnectionField [as 别名]
def test_should_manytomany_convert_connectionorlist_connection():
class A(DjangoObjectType):
class Meta:
model = Reporter
interfaces = (Node,)
graphene_field = convert_django_field(
Reporter._meta.local_many_to_many[0], A._meta.registry
)
assert isinstance(graphene_field, graphene.Dynamic)
dynamic_field = graphene_field.get_type()
assert isinstance(dynamic_field, ConnectionField)
assert dynamic_field.type.of_type == A._meta.connection
示例6: _field_args
# 需要导入模块: from graphene import relay [as 别名]
# 或者: from graphene.relay import ConnectionField [as 别名]
def _field_args(self, items):
def is_filterable(k):
"""
Remove complex columns from input args at this moment.
Args:
k (str): field name.
Returns:
bool
"""
if not hasattr(self.model, k):
return False
if isinstance(getattr(self.model, k), property):
return False
try:
converted = convert_mongoengine_field(
getattr(self.model, k), self.registry
)
except MongoEngineConversionError:
return False
if isinstance(converted, (ConnectionField, Dynamic)):
return False
if callable(getattr(converted, "type", None)) and isinstance(
converted.type(),
(
FileFieldType,
PointFieldType,
MultiPolygonFieldType,
graphene.Union,
PolygonFieldType,
),
):
return False
if isinstance(converted, (graphene.List)) and issubclass(
getattr(converted, "_of_type", None), graphene.Union
):
return False
return True
def get_filter_type(_type):
"""
Returns the scalar type.
"""
if isinstance(_type, Structure):
return get_filter_type(_type.of_type)
return _type()
return {k: get_filter_type(v.type) for k, v in items if is_filterable(k)}