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


Python graphene.NonNull方法代码示例

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


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

示例1: __init__

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import NonNull [as 别名]
def __init__(self, ndb_key_prop, graphql_type_name, *args, **kwargs):
        self.__ndb_key_prop = ndb_key_prop
        self.__graphql_type_name = graphql_type_name
        is_repeated = ndb_key_prop._repeated
        is_required = ndb_key_prop._required

        _type = String
        if is_repeated:
            _type = List(_type)

        if is_required:
            _type = NonNull(_type)

        kwargs['args'] = {
            'ndb': Argument(Boolean, False, description="Return an NDB id (key.id()) instead of a GraphQL global id")
        }

        super(NdbKeyStringField, self).__init__(_type, *args, **kwargs) 
开发者ID:graphql-python,项目名称:graphene-gae,代码行数:20,代码来源:fields.py

示例2: convert_local_structured_property

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import NonNull [as 别名]
def convert_local_structured_property(ndb_structured_property, registry=None):
    is_required = ndb_structured_property._required
    is_repeated = ndb_structured_property._repeated
    model = ndb_structured_property._modelclass
    name = ndb_structured_property._code_name

    def dynamic_type():
        _type = registry.get_type_for_model(model)
        if not _type:
            return None

        if is_repeated:
            _type = List(_type)

        if is_required:
            _type = NonNull(_type)

        return Field(_type)

    field = Dynamic(dynamic_type)
    return ConversionResult(name=name, field=field) 
开发者ID:graphql-python,项目名称:graphene-gae,代码行数:23,代码来源:converter.py

示例3: _range_filter_type

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import NonNull [as 别名]
def _range_filter_type(
    type_: 'GRAPHENE_OBJECT_OR_CLASS', _: bool, doc: str
) -> graphene.InputObjectType:
    of_type = _get_class(type_)

    with contextlib.suppress(KeyError):
        return _range_filter_cache[of_type]

    element_type = graphene.NonNull(of_type)
    klass = type(
        str(of_type) + 'Range',
        (graphene.InputObjectType,),
        {RANGE_BEGIN: element_type, RANGE_END: element_type},
    )
    result = klass(description=doc)
    _range_filter_cache[of_type] = result
    return result 
开发者ID:art1415926535,项目名称:graphene-sqlalchemy-filter,代码行数:19,代码来源:filters.py

示例4: test_conjunction_filter_field_types

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import NonNull [as 别名]
def test_conjunction_filter_field_types():
    filter_fields = deepcopy(UserFilter._meta.fields)

    for op in [UserFilter.AND, UserFilter.OR]:
        assert op in filter_fields
        assert isinstance(filter_fields[op], graphene.InputField)

        input_field = filter_fields[op].type
        assert isinstance(input_field, graphene.List)

        input_field_of_type = input_field.of_type
        assert isinstance(input_field_of_type, graphene.NonNull)

        non_null_input_field_of_type = input_field_of_type.of_type
        assert non_null_input_field_of_type is UserFilter

        del filter_fields[op] 
开发者ID:art1415926535,项目名称:graphene-sqlalchemy-filter,代码行数:19,代码来源:test_filter_set.py

示例5: type

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import NonNull [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 
开发者ID:graphql-python,项目名称:graphene-django,代码行数:20,代码来源:fields.py

示例6: test_should_manytomany_convert_connectionorlist_list

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import NonNull [as 别名]
def test_should_manytomany_convert_connectionorlist_list():
    class A(DjangoObjectType):
        class Meta:
            model = Reporter

    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, graphene.Field)
    # A NonNull List of NonNull A ([A!]!)
    # https://github.com/graphql-python/graphene-django/issues/448
    assert isinstance(dynamic_field.type, NonNull)
    assert isinstance(dynamic_field.type.of_type, graphene.List)
    assert isinstance(dynamic_field.type.of_type.of_type, NonNull)
    assert dynamic_field.type.of_type.of_type.of_type == A 
开发者ID:graphql-python,项目名称:graphene-django,代码行数:19,代码来源:test_converter.py

示例7: test_should_postgres_array_multiple_convert_list

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import NonNull [as 别名]
def test_should_postgres_array_multiple_convert_list():
    field = assert_conversion(
        ArrayField, graphene.List, ArrayField(models.CharField(max_length=100))
    )
    assert isinstance(field.type, graphene.NonNull)
    assert isinstance(field.type.of_type, graphene.List)
    assert isinstance(field.type.of_type.of_type, graphene.List)
    assert isinstance(field.type.of_type.of_type.of_type, graphene.NonNull)
    assert field.type.of_type.of_type.of_type.of_type == graphene.String

    field = assert_conversion(
        ArrayField,
        graphene.List,
        ArrayField(models.CharField(max_length=100, null=True)),
    )
    assert isinstance(field.type, graphene.NonNull)
    assert isinstance(field.type.of_type, graphene.List)
    assert isinstance(field.type.of_type.of_type, graphene.List)
    assert field.type.of_type.of_type.of_type == graphene.String 
开发者ID:graphql-python,项目名称:graphene-django,代码行数:21,代码来源:test_converter.py

示例8: convert_ndb_scalar_property

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import NonNull [as 别名]
def convert_ndb_scalar_property(graphene_type, ndb_prop, registry=None, **kwargs):
    kwargs['description'] = "%s %s property" % (ndb_prop._name, graphene_type)
    _type = graphene_type

    if ndb_prop._repeated:
        _type = List(_type)

    if ndb_prop._required:
        _type = NonNull(_type)

    return Field(_type, **kwargs) 
开发者ID:graphql-python,项目名称:graphene-gae,代码行数:13,代码来源:converter.py

示例9: testStringProperty_required_shouldConvertToList

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import NonNull [as 别名]
def testStringProperty_required_shouldConvertToList(self):
        ndb_prop = ndb.StringProperty(required=True)
        result = convert_ndb_property(ndb_prop)
        graphene_type = result.field._type

        self.assertIsInstance(graphene_type, graphene.NonNull)
        self.assertEqual(graphene_type.of_type, graphene.String) 
开发者ID:graphql-python,项目名称:graphene-gae,代码行数:9,代码来源:test_converter.py

示例10: get_type

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import NonNull [as 别名]
def get_type(self):
        """
        This function is called when the unmounted type (List or NonNull instance)
        is mounted (as a Field, InputField or Argument)
        """
        return self 
开发者ID:graphql-python,项目名称:graphene,代码行数:8,代码来源:structures.py

示例11: __init__

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import NonNull [as 别名]
def __init__(self, *args, **kwargs):
        super(NonNull, self).__init__(*args, **kwargs)
        assert not isinstance(
            self._of_type, NonNull
        ), f"Can only create NonNull of a Nullable GraphQLType but got: {self._of_type}." 
开发者ID:graphql-python,项目名称:graphene,代码行数:7,代码来源:structures.py

示例12: __eq__

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import NonNull [as 别名]
def __eq__(self, other):
        return isinstance(other, NonNull) and (
            self.of_type == other.of_type
            and self.args == other.args
            and self.kwargs == other.kwargs
        ) 
开发者ID:graphql-python,项目名称:graphene,代码行数:8,代码来源:structures.py

示例13: __init__

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import NonNull [as 别名]
def __init__(
        self, _type, ordering="-created", cursor_query_param="cursor", *args, **kwargs
    ):
        kwargs.setdefault("args", {})

        self.page_size = graphql_api_settings.DEFAULT_PAGE_SIZE
        self.page_size_query_param = "page_size" if not self.page_size else None
        self.cursor_query_param = cursor_query_param
        self.ordering = ordering
        self.cursor_query_description = "The pagination cursor value."
        self.page_size_query_description = "Number of results to return per page."

        kwargs[self.cursor_query_param] = NonNull(
            String, description=self.cursor_query_description
        )

        if self.page_size_query_param:
            if not self.page_size:
                kwargs[self.page_size_query_param] = NonNull(
                    Int, description=self.page_size_query_description
                )
            else:
                kwargs[self.page_size_query_param] = Int(
                    description=self.page_size_query_description
                )

        super(CursorPaginationField, self).__init__(List(_type), *args, **kwargs) 
开发者ID:eamigo86,项目名称:graphene-django-extras,代码行数:29,代码来源:fields.py

示例14: to_graphql_fields

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import NonNull [as 别名]
def to_graphql_fields(self):
        return {
            self.cursor_query_param: NonNull(
                String, description=self.cursor_query_description
            )
        } 
开发者ID:eamigo86,项目名称:graphene-django-extras,代码行数:8,代码来源:pagination.py

示例15: _in_filter_type

# 需要导入模块: import graphene [as 别名]
# 或者: from graphene import NonNull [as 别名]
def _in_filter_type(
    type_: 'GRAPHENE_OBJECT_OR_CLASS', nullable: bool, doc: str
) -> graphene.List:
    of_type = type_

    if not isinstance(of_type, graphene.List):
        of_type = _get_class(type_)

    if not nullable:
        of_type = graphene.NonNull(of_type)

    filter_field = graphene.List(of_type, description=doc)
    return filter_field 
开发者ID:art1415926535,项目名称:graphene-sqlalchemy-filter,代码行数:15,代码来源:filters.py


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