本文整理汇总了Python中graphene.relay.Connection方法的典型用法代码示例。如果您正苦于以下问题:Python relay.Connection方法的具体用法?Python relay.Connection怎么用?Python relay.Connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graphene.relay
的用法示例。
在下文中一共展示了relay.Connection方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: type
# 需要导入模块: from graphene import relay [as 别名]
# 或者: from graphene.relay import Connection [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: __init__
# 需要导入模块: from graphene import relay [as 别名]
# 或者: from graphene.relay import Connection [as 别名]
def __init__(self, type, *args, **kwargs):
nullable_type = get_nullable_type(type)
if "sort" not in kwargs and issubclass(nullable_type, Connection):
# Let super class raise if type is not a Connection
try:
kwargs.setdefault("sort", nullable_type.Edge.node._type.sort_argument())
except (AttributeError, TypeError):
raise TypeError(
'Cannot create sort argument for {}. A model is required. Set the "sort" argument'
" to None to disabling the creation of the sort query argument".format(
nullable_type.__name__
)
)
elif "sort" in kwargs and kwargs["sort"] is None:
del kwargs["sort"]
super(SQLAlchemyConnectionField, self).__init__(type, *args, **kwargs)
示例3: test_nonnull_sqlalachemy_connection
# 需要导入模块: from graphene import relay [as 别名]
# 或者: from graphene.relay import Connection [as 别名]
def test_nonnull_sqlalachemy_connection():
field = SQLAlchemyConnectionField(NonNull(Pet.connection))
assert isinstance(field.type, NonNull)
assert issubclass(field.type.of_type, Connection)
assert field.type.of_type._meta.node is Pet
示例4: test_required_sqlalachemy_connection
# 需要导入模块: from graphene import relay [as 别名]
# 或者: from graphene.relay import Connection [as 别名]
def test_required_sqlalachemy_connection():
field = SQLAlchemyConnectionField(Pet.connection, required=True)
assert isinstance(field.type, NonNull)
assert issubclass(field.type.of_type, Connection)
assert field.type.of_type._meta.node is Pet
示例5: test_sort_init_raises
# 需要导入模块: from graphene import relay [as 别名]
# 或者: from graphene.relay import Connection [as 别名]
def test_sort_init_raises():
with pytest.raises(TypeError, match="Cannot create sort"):
SQLAlchemyConnectionField(Connection)