Python graphene.Int() Examples

The following are 30 code examples of graphene.Int(). 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: images.py    From wagtail-graphql with MIT License 6 votes vote down vote up
def ImageQueryMixin():
    class Mixin:
        images = graphene.List(Image)
        image = graphene.Field(Image,
                               id=graphene.Int(required=True))

        def resolve_images(self, info: ResolveInfo):
            return with_collection_permissions(
                info.context,
                gql_optimizer.query(
                    wagtailImage.objects.all(),
                    info
                )
            )

        def resolve_image(self, info: ResolveInfo, id: int):
            image = with_collection_permissions(
                info.context,
                gql_optimizer.query(
                    wagtailImage.objects.filter(id=id),
                    info
                )
            ).first()
            return image
    return Mixin 
Example #2
Source File: pagination.py    From graphene-django-extras with MIT License 6 votes vote down vote up
def to_graphql_fields(self):
        return {
            self.limit_query_param: Int(
                default_value=self.default_limit,
                description="Number of results to return per page. Default "
                "'default_limit': {}, and 'max_limit': {}".format(
                    self.default_limit, self.max_limit
                ),
            ),
            self.offset_query_param: Int(
                description="The initial index from which to return the results. Default: 0"
            ),
            self.ordering_param: String(
                description="A string or comma delimited string values that indicate the "
                "default ordering when obtaining lists of objects."
            ),
        } 
Example #3
Source File: documents.py    From wagtail-graphql with MIT License 6 votes vote down vote up
def DocumentQueryMixin():
    class Mixin:
        documents = graphene.List(Document)
        document = graphene.Field(Document,
                                  id=graphene.Int(required=True))

        def resolve_documents(self, info: ResolveInfo):
            return with_collection_permissions(
                info.context,
                gql_optimizer.query(
                    wagtailDocument.objects.all(),
                    info
                )
            )

        def resolve_document(self, info: ResolveInfo, id: int):
            doc = with_collection_permissions(
                info.context,
                gql_optimizer.query(
                    wagtailDocument.objects.filter(id=id),
                    info
                )
            ).first()
            return doc
    return Mixin 
Example #4
Source File: type.py    From lutece-backend with GNU General Public License v3.0 5 votes vote down vote up
def resolve_tried(self, info: ResolveInfo) -> graphene.Int:
        return self.tried 
Example #5
Source File: test_converter.py    From graphene-django with MIT License 5 votes vote down vote up
def test_should_positive_small_convert_int():
    assert_conversion(models.PositiveSmallIntegerField, graphene.Int) 
Example #6
Source File: test_converter.py    From graphene-django with MIT License 5 votes vote down vote up
def test_should_small_integer_convert_int():
    assert_conversion(models.SmallIntegerField, graphene.Int) 
Example #7
Source File: test_converter.py    From graphene-django with MIT License 5 votes vote down vote up
def test_should_big_integer_convert_int():
    assert_conversion(models.BigIntegerField, graphene.Int) 
Example #8
Source File: test_converter.py    From graphene-django with MIT License 5 votes vote down vote up
def test_should_integer_convert_int():
    assert_conversion(models.IntegerField, graphene.Int) 
Example #9
Source File: test_subscription_manager.py    From graphql-python-subscriptions with MIT License 5 votes vote down vote up
def schema():
    class Query(graphene.ObjectType):
        test_string = graphene.String()

        def resolve_test_string(self, args, context, info):
            return 'works'

    # TODO: Implement case conversion for arg names
    class Subscription(graphene.ObjectType):
        test_subscription = graphene.String()
        test_context = graphene.String()
        test_filter = graphene.String(filterBoolean=graphene.Boolean())
        test_filter_multi = graphene.String(
            filterBoolean=graphene.Boolean(),
            a=graphene.String(),
            b=graphene.Int())
        test_channel_options = graphene.String()

        def resolve_test_subscription(self, args, context, info):
            return self

        def resolve_test_context(self, args, context, info):
            return context

        def resolve_test_filter(self, args, context, info):
            return 'good_filter' if args.get('filterBoolean') else 'bad_filter'

        def resolve_test_filter_multi(self, args, context, info):
            return 'good_filter' if args.get('filterBoolean') else 'bad_filter'

        def resolve_test_channel_options(self, args, context, info):
            return self

    return graphene.Schema(query=Query, subscription=Subscription) 
Example #10
Source File: type.py    From lutece-backend with GNU General Public License v3.0 5 votes vote down vote up
def resolve_vote(self, info: ResolveInfo) -> graphene.Int():
        return self.vote 
Example #11
Source File: type.py    From lutece-backend with GNU General Public License v3.0 5 votes vote down vote up
def resolve_total_reply_number(self, info: ResolveInfo) -> graphene.Int():
        return BaseReply.objects.filter(ancestor=self).count() 
Example #12
Source File: type.py    From lutece-backend with GNU General Public License v3.0 5 votes vote down vote up
def resolve_solved(self, info: ResolveInfo) -> graphene.Int:
        return self.solved 
Example #13
Source File: fields.py    From graphene-gae with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, type, transform_edges=None, *args, **kwargs):
        super(NdbConnectionField, self).__init__(
            type,
            *args,
            keys_only=Boolean(),
            batch_size=Int(),
            page_size=Int(),
            **kwargs
        )

        self.transform_edges = transform_edges 
Example #14
Source File: type.py    From lutece-backend with GNU General Public License v3.0 5 votes vote down vote up
def resolve_standard_submit(self, info: ResolveInfo) -> graphene.Int():
        return self.submit 
Example #15
Source File: type.py    From lutece-backend with GNU General Public License v3.0 5 votes vote down vote up
def resolve_data_count(self, info: ResolveInfo) -> graphene.Int:
        return DataService.get_cases_count(self.pk) 
Example #16
Source File: type.py    From lutece-backend with GNU General Public License v3.0 5 votes vote down vote up
def resolve_submit(self, info: ResolveInfo) -> graphene.Int():
        contest = Contest.objects.get(pk=info.variable_values.get('pk'))
        return ContestSubmission.objects.filter(Q(contest=contest) & Q(problem=self) & ~Q(team=None)).count() 
Example #17
Source File: type.py    From lutece-backend with GNU General Public License v3.0 5 votes vote down vote up
def resolve_accept(self, info: ResolveInfo) -> graphene.Int():
        contest = Contest.objects.get(pk=info.variable_values.get('pk'))
        return ContestSubmission.objects.filter(
            Q(contest=contest) & Q(problem=self) & ~Q(team=None) & Q(result___result=JudgeResult.AC.full)).values(
            'team').distinct().count() 
Example #18
Source File: type.py    From lutece-backend with GNU General Public License v3.0 5 votes vote down vote up
def resolve_max_team_member_number(self, info: ResolveInfo) -> graphene.Int():
        return self.max_team_member_number 
Example #19
Source File: type.py    From lutece-backend with GNU General Public License v3.0 5 votes vote down vote up
def resolve_register_member_number(self, info: ResolveInfo) -> graphene.Int():
        return ContestTeamMember.objects.filter(contest_team__contest=self, contest_team__approved=True,
                                                confirmed=True).count() 
Example #20
Source File: query.py    From lutece-backend with GNU General Public License v3.0 5 votes vote down vote up
def resolve_contest_clarification_list(self: None, info: ResolveInfo, pk: graphene.ID(), page: graphene.Int()):
        contest = get_object_or_None(Contest, pk=pk)
        privilege = info.context.user.has_perm('contest.view_contest')
        if datetime.now() < contest.settings.start_time and not privilege:
            return ContestClarificationListType(max_page=1, contest_clarification_list=[])
        if not contest:
            raise GraphQLError('No such contest')
        clarification_list = ContestClarification.objects.filter(contest=contest)
        privilege = info.context.user.has_perm('contest.view_contestclarification')
        if not privilege:
            clarification_list = clarification_list.filter(disable=False)
        clarification_list = clarification_list.order_by('-vote')
        paginator = Paginator(clarification_list, CLARIFICATION_PER_PAGE_COUNT)
        return ContestClarificationListType(max_page=paginator.num_pages,
                                            contest_clarification_list=paginator.get_page(page)) 
Example #21
Source File: type.py    From lutece-backend with GNU General Public License v3.0 5 votes vote down vote up
def resolve_vote(self, info: ResolveInfo) -> graphene.Int():
        return ArticleVote.objects.filter(article=self, attitude=True).count() 
Example #22
Source File: type.py    From lutece-backend with GNU General Public License v3.0 5 votes vote down vote up
def resolve_rank(self, info: ResolveInfo) -> graphene.Int():
        return self.rank 
Example #23
Source File: object_types.py    From flask-unchained with MIT License 5 votes vote down vote up
def convert_column_to_int_or_id(type, column, registry=None):
    if column.primary_key or column.foreign_keys:
        return graphene.ID(
            description=get_column_doc(column),
            required=not (is_column_nullable(column)),
        )
    else:
        return graphene.Int(
            description=get_column_doc(column),
            required=not (is_column_nullable(column)),
        ) 
Example #24
Source File: database.py    From king-phisher with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def connection_factory(cls, node):
		name = node.__name__ + 'Connection'
		if name in cls.__connection_types:
			return cls.__connection_types[name]
		connection_type = type(
			node.__name__ + 'Connection',
			(graphene.relay.Connection,),
			{
				'Meta': type('Meta', (), {'node': node}),
				'total': graphene.Int()
			}
		)
		cls.__connection_types[name] = connection_type
		return connection_type 
Example #25
Source File: converter.py    From graphene-gae with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def convert_ndb_int_property(ndb_prop, registry=None):
    return convert_ndb_scalar_property(Int, ndb_prop) 
Example #26
Source File: test_converter.py    From graphene-gae with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def testIntProperty_shouldConvertToString(self):
        self.__assert_conversion(ndb.IntegerProperty, graphene.Int) 
Example #27
Source File: fields.py    From graphene-django-extras with MIT License 5 votes vote down vote up
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 #28
Source File: pagination.py    From graphene-django-extras with MIT License 5 votes vote down vote up
def to_graphql_fields(self):
        paginator_dict = {
            self.page_query_param: Int(
                default_value=1,
                description="A page number within the result paginated set. Default: 1",
            ),
            self.ordering_param: String(
                description="A string or comma delimited string values that indicate the "
                "default ordering when obtaining lists of objects."
            ),
        }

        if self.page_size_query_param:
            paginator_dict.update(
                {
                    self.page_size_query_param: Int(
                        description=self.page_size_query_description
                    )
                }
            )

        return paginator_dict 
Example #29
Source File: utils.py    From graphql-pynamodb with MIT License 5 votes vote down vote up
def connection_for_type(_type):
    class Connection(graphene.relay.Connection):
        total_count = graphene.Int()

        class Meta:
            name = _type._meta.name + 'Connection'
            node = _type

        def resolve_total_count(self, args, context, info):
            return self.total_count if hasattr(self, "total_count") else len(self.edges)

    return Connection 
Example #30
Source File: converter.py    From graphene-mongo with MIT License 5 votes vote down vote up
def convert_field_to_int(field, registry=None):
    return graphene.Int(
        description=get_field_description(field, registry), required=field.required
    )