Python graphene.NonNull() Examples
The following are 30
code examples of graphene.NonNull().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
graphene
, or try the search function
.
Example #1
Source File: test_converter.py From graphene-django with MIT License | 6 votes |
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
Example #2
Source File: converter.py From graphene-gae with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #3
Source File: fields.py From graphene-gae with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #4
Source File: test_converter.py From graphene-django with MIT License | 6 votes |
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
Example #5
Source File: test_filter_set.py From graphene-sqlalchemy-filter with MIT License | 6 votes |
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]
Example #6
Source File: fields.py From graphene-django with MIT License | 6 votes |
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
Example #7
Source File: filters.py From graphene-sqlalchemy-filter with MIT License | 6 votes |
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
Example #8
Source File: fields.py From graphene-django with MIT License | 5 votes |
def connection_type(self): type = self.type if isinstance(type, NonNull): return type.of_type return type
Example #9
Source File: test_converter.py From graphene-sqlalchemy with MIT License | 5 votes |
def test_should_primary_integer_convert_id(): assert get_field(types.Integer(), primary_key=True).type == graphene.NonNull(graphene.ID)
Example #10
Source File: fields.py From graphene-mongo with MIT License | 5 votes |
def connection_resolver(cls, resolver, connection_type, root, info, **args): iterable = resolver(root, info, **args) if isinstance(connection_type, graphene.NonNull): connection_type = connection_type.of_type on_resolve = partial(cls.resolve_connection, connection_type, args) if Promise.is_thenable(iterable): return Promise.resolve(iterable).then(on_resolve) return on_resolve(iterable)
Example #11
Source File: converter.py From graphene-mongo with MIT License | 5 votes |
def convert_field_to_list(field, registry=None): base_type = convert_mongoengine_field(field.field, registry=registry) if isinstance(base_type, graphene.Field): return graphene.List( base_type._type, description=get_field_description(field, registry), required=field.required ) if isinstance(base_type, (graphene.Dynamic)): base_type = base_type.get_type() if base_type is None: return base_type = base_type._type if graphene.is_node(base_type): return base_type._meta.connection_field_class(base_type) # Non-relationship field relations = (mongoengine.ReferenceField, mongoengine.EmbeddedDocumentField) if not isinstance(base_type, (graphene.List, graphene.NonNull)) and not isinstance( field.field, relations ): base_type = type(base_type) return graphene.List( base_type, description=get_field_description(field, registry), required=field.required, )
Example #12
Source File: fields.py From graphene-django with MIT License | 5 votes |
def __init__(self, _type, *args, **kwargs): from .types import DjangoObjectType if isinstance(_type, NonNull): _type = _type.of_type # Django would never return a Set of None vvvvvvv super(DjangoListField, self).__init__(List(NonNull(_type)), *args, **kwargs) assert issubclass( self._underlying_type, DjangoObjectType ), "DjangoListField only accepts DjangoObjectType types"
Example #13
Source File: fields.py From graphene-django with MIT License | 5 votes |
def get_resolver(self, parent_resolver): _type = self.type if isinstance(_type, NonNull): _type = _type.of_type django_object_type = _type.of_type.of_type return partial( self.list_resolver, django_object_type, parent_resolver, self.get_default_queryset(), )
Example #14
Source File: fields.py From graphene-sqlalchemy with MIT License | 5 votes |
def get_nullable_type(_type): if isinstance(_type, NonNull): return _type.of_type return _type
Example #15
Source File: test_fields.py From graphene-django with MIT License | 5 votes |
def test_non_null_type(self): class Reporter(DjangoObjectType): class Meta: model = ReporterModel fields = ("first_name",) list_field = DjangoListField(NonNull(Reporter)) assert isinstance(list_field.type, List) assert isinstance(list_field.type.of_type, NonNull) assert list_field.type.of_type.of_type is Reporter
Example #16
Source File: test_converter.py From graphene-django with MIT License | 5 votes |
def test_should_boolean_convert_non_null_boolean(): field = assert_conversion(models.BooleanField, graphene.Boolean, null=False) assert isinstance(field.type, graphene.NonNull) assert field.type.of_type == graphene.Boolean
Example #17
Source File: test_converter.py From graphene-django with MIT License | 5 votes |
def test_should_manytoone_convert_connectionorlist(): class A(DjangoObjectType): class Meta: model = Article graphene_field = convert_django_field(Reporter.articles.rel, 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!]!) 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
Example #18
Source File: test_converter.py From graphene-django with MIT License | 5 votes |
def test_should_postgres_array_convert_list(): field = assert_conversion( ArrayField, graphene.List, 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.NonNull) assert field.type.of_type.of_type.of_type == graphene.String field = assert_conversion( ArrayField, graphene.List, models.CharField(max_length=100, null=True) ) assert isinstance(field.type, graphene.NonNull) assert isinstance(field.type.of_type, graphene.List) assert field.type.of_type.of_type == graphene.String
Example #19
Source File: mutations.py From graphene-django-plus with MIT License | 5 votes |
def _is_id_field(field): return ( field.type == graphene.ID or isinstance(field.type, graphene.NonNull) and field.type.of_type == graphene.ID )
Example #20
Source File: test_fields.py From graphene-sqlalchemy with MIT License | 5 votes |
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
Example #21
Source File: test_fields.py From graphene-sqlalchemy with MIT License | 5 votes |
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
Example #22
Source File: dauphin_registry.py From dagster with Apache License 2.0 | 5 votes |
def create_registry_nonnull(registry): class NonNull(graphene.NonNull): def __init__(self, of_type, *args, **kwargs): super(NonNull, self).__init__(get_type_fn(registry, of_type), *args, **kwargs) return NonNull
Example #23
Source File: dauphin_registry.py From dagster with Apache License 2.0 | 5 votes |
def non_null_list(self, of_type): return self.NonNull(self.List(self.NonNull(of_type)))
Example #24
Source File: filters.py From graphene-sqlalchemy-filter with MIT License | 5 votes |
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
Example #25
Source File: pagination.py From graphene-django-extras with MIT License | 5 votes |
def to_graphql_fields(self): return { self.cursor_query_param: NonNull( String, description=self.cursor_query_description ) }
Example #26
Source File: fields.py From graphene-django-extras with MIT License | 5 votes |
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)
Example #27
Source File: structures.py From graphene with MIT License | 5 votes |
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 )
Example #28
Source File: structures.py From graphene with MIT License | 5 votes |
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}."
Example #29
Source File: structures.py From graphene with MIT License | 5 votes |
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
Example #30
Source File: test_converter.py From graphene-gae with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)