Python graphene.Boolean() Examples

The following are 30 code examples of graphene.Boolean(). 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: fields.py    From graphene-gae with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #2
Source File: test_fields.py    From graphene-django with MIT License 5 votes vote down vote up
def test_node_get_queryset_is_called():
    class ReporterType(DjangoObjectType):
        class Meta:
            model = Reporter
            interfaces = (Node,)
            filter_fields = ()

        @classmethod
        def get_queryset(cls, queryset, info):
            return queryset.filter(first_name="b")

    class Query(ObjectType):
        all_reporters = DjangoFilterConnectionField(
            ReporterType, reverse_order=Boolean()
        )

    Reporter.objects.create(first_name="b")
    Reporter.objects.create(first_name="a")

    schema = Schema(query=Query)
    query = """
        query NodeFilteringQuery {
            allReporters(first: 10) {
                edges {
                    node {
                        firstName
                    }
                }
            }
        }
    """
    expected = {"allReporters": {"edges": [{"node": {"firstName": "b"}}]}}

    result = schema.execute(query)
    assert not result.errors
    assert result.data == expected 
Example #3
Source File: type.py    From lutece-backend with GNU General Public License v3.0 5 votes vote down vote up
def resolve_disable(self, info: ResolveInfo) -> graphene.Boolean():
        return self.disable 
Example #4
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 #5
Source File: test_subscription_manager.py    From graphql-python-subscriptions with MIT License 5 votes vote down vote up
def test_use_filter_functions_properly(sub_mgr):
    query = 'subscription Filter1($filterBoolean: Boolean) {\
    testFilter(filterBoolean: $filterBoolean)}'

    def callback(err, payload):
        if err:
            sys.exit(err)
        else:
            try:
                if payload is None:
                    assert True
                else:
                    assert payload.data.get('testFilter') == 'good_filter'
                    sub_mgr.pubsub.greenlet.kill()
            except AssertionError as e:
                sys.exit(e)

    def publish_and_unsubscribe_handler(sub_id):
        sub_mgr.publish('filter_1', {'filterBoolean': False})
        sub_mgr.publish('filter_1', {'filterBoolean': True})
        sub_mgr.pubsub.greenlet.join()
        sub_mgr.unsubscribe(sub_id)

    p1 = sub_mgr.subscribe(query, 'Filter1', callback, {'filterBoolean': True},
                           {}, None, None)
    p2 = p1.then(publish_and_unsubscribe_handler)
    p2.get() 
Example #6
Source File: test_subscription_manager.py    From graphql-python-subscriptions with MIT License 5 votes vote down vote up
def test_use_filter_func_that_returns_a_promise(sub_mgr):
    query = 'subscription Filter2($filterBoolean: Boolean) {\
    testFilter(filterBoolean: $filterBoolean)}'

    def callback(err, payload):
        if err:
            sys.exit(err)
        else:
            try:
                if payload is None:
                    assert True
                else:
                    assert payload.data.get('testFilter') == 'good_filter'
                    sub_mgr.pubsub.greenlet.kill()
            except AssertionError as e:
                sys.exit(e)

    def publish_and_unsubscribe_handler(sub_id):
        sub_mgr.publish('filter_2', {'filterBoolean': False})
        sub_mgr.publish('filter_2', {'filterBoolean': True})
        try:
            sub_mgr.pubsub.greenlet.join()
        except:
            raise
        sub_mgr.unsubscribe(sub_id)

    p1 = sub_mgr.subscribe(query, 'Filter2', callback, {'filterBoolean': True},
                           {}, None, None)
    p2 = p1.then(publish_and_unsubscribe_handler)
    p2.get() 
Example #7
Source File: test_subscription_manager.py    From graphql-python-subscriptions with MIT License 5 votes vote down vote up
def test_can_subscribe_to_more_than_one_trigger(sub_mgr):
    non_local = {'trigger_count': 0}

    query = 'subscription multiTrigger($filterBoolean: Boolean,\
            $uga: String){testFilterMulti(filterBoolean: $filterBoolean,\
            a: $uga, b: 66)}'

    def callback(err, payload):
        if err:
            sys.exit(err)
        else:
            try:
                if payload is None:
                    assert True
                else:
                    assert payload.data.get('testFilterMulti') == 'good_filter'
                    non_local['trigger_count'] += 1
            except AssertionError as e:
                sys.exit(e)
        if non_local['trigger_count'] == 2:
            sub_mgr.pubsub.greenlet.kill()

    def publish_and_unsubscribe_handler(sub_id):
        sub_mgr.publish('not_a_trigger', {'filterBoolean': False})
        sub_mgr.publish('trigger_1', {'filterBoolean': True})
        sub_mgr.publish('trigger_2', {'filterBoolean': True})
        sub_mgr.pubsub.greenlet.join()
        sub_mgr.unsubscribe(sub_id)

    p1 = sub_mgr.subscribe(query, 'multiTrigger', callback,
                           {'filterBoolean': True,
                            'uga': 'UGA'}, {}, None, None)
    p2 = p1.then(publish_and_unsubscribe_handler)
    p2.get() 
Example #8
Source File: test_subscription_manager.py    From graphql-python-subscriptions with MIT License 5 votes vote down vote up
def test_calls_the_error_callback_if_there_is_an_execution_error(sub_mgr):
    query = 'subscription X($uga: Boolean!){\
        testSubscription  @skip(if: $uga)\
    }'

    def callback(err, payload):
        try:
            assert payload is None
            assert err.message == 'Variable "$uga" of required type\
 "Boolean!" was not provided.'

            sub_mgr.pubsub.greenlet.kill()
        except AssertionError as e:
            sys.exit(e)

    def unsubscribe_and_publish_handler(sub_id):
        sub_mgr.publish('testSubscription', 'good')
        try:
            sub_mgr.pubsub.greenlet.join()
        except AttributeError:
            return
        sub_mgr.unsubscribe(sub_id)

    p1 = sub_mgr.subscribe(
        query,
        operation_name='X',
        callback=callback,
        variables={},
        context={},
        format_error=None,
        format_response=None)
    p2 = p1.then(unsubscribe_and_publish_handler)
    p2.get() 
Example #9
Source File: type.py    From lutece-backend with GNU General Public License v3.0 5 votes vote down vote up
def resolve_self_attitude(self, info: ResolveInfo) -> graphene.Boolean():
        usr = info.context.user
        if not usr.is_authenticated:
            return False
        vote = get_object_or_None(ReplyVote, reply=self, record_user=usr)
        return vote.attitude if vote else False 
Example #10
Source File: type.py    From lutece-backend with GNU General Public License v3.0 5 votes vote down vote up
def resolve_disable(self, info: ResolveInfo) -> graphene.Boolean():
        return self.disable 
Example #11
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.Boolean():
        usr = info.context.user
        if not usr.is_authenticated:
            return False
        contest = Contest.objects.get(pk=info.variable_values.get('pk'))
        team = get_object_or_None(ContestTeam, contest=contest, memeber__user=usr, memeber__confirmed=True)
        return ContestSubmission.objects.filter(contest=contest, team=team, problem=self).exists() 
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.Boolean():
        usr = info.context.user
        if not usr.is_authenticated:
            return False
        contest = Contest.objects.get(pk=info.variable_values.get('pk'))
        team = get_object_or_None(ContestTeam, contest=contest, memeber__user=usr, memeber__confirmed=True)
        return ContestSubmission.objects.filter(contest=contest, team=team, problem=self,
                                                result___result=JudgeResult.AC.full).exists() 
Example #13
Source File: type.py    From lutece-backend with GNU General Public License v3.0 5 votes vote down vote up
def resolve_disable(self, info: ResolveInfo) -> graphene.Boolean():
        return self.disable 
Example #14
Source File: type.py    From lutece-backend with GNU General Public License v3.0 5 votes vote down vote up
def resolve_registered(self, info: ResolveInfo) -> graphene.Boolean():
        usr = info.context.user
        if not usr.is_authenticated:
            return False
        member = get_object_or_None(ContestTeamMember, user=usr, contest_team__contest=self, confirmed=True)
        return usr.has_perm('contest.view_contest') or (member and member.contest_team.approved) 
Example #15
Source File: type.py    From lutece-backend with GNU General Public License v3.0 5 votes vote down vote up
def resolve_is_public(self, info: ResolveInfo) -> graphene.Boolean():
        return self.is_public() 
Example #16
Source File: type.py    From lutece-backend with GNU General Public License v3.0 5 votes vote down vote up
def resolve_approved(self, info: ResolveInfo) -> graphene.Boolean:
        return self.approved 
Example #17
Source File: type.py    From lutece-backend with GNU General Public License v3.0 5 votes vote down vote up
def resolve_self_attitude(self, info: ResolveInfo) -> graphene.Boolean():
        usr = info.context.user
        if not usr.is_authenticated:
            return False
        vote = get_object_or_None(ArticleVote, article=self, record_user=usr)
        return vote.attitude if vote else False 
Example #18
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 #19
Source File: converter.py    From graphene-gae with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def convert_ndb_boolean_property(ndb_prop, registry=None):
    return convert_ndb_scalar_property(Boolean, ndb_prop) 
Example #20
Source File: test_converter.py    From graphene-django with MIT License 5 votes vote down vote up
def test_should_boolean_convert_boolean():
    assert_conversion(models.BooleanField, graphene.Boolean, null=True) 
Example #21
Source File: test_converter.py    From graphene-gae with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def testBoolProperty_shouldConvertToString(self):
        self.__assert_conversion(ndb.BooleanProperty, graphene.Boolean) 
Example #22
Source File: test_context.py    From DjangoChannelsGraphqlWs with MIT License 5 votes vote down vote up
def test_context_lifetime(gql):
    """Check that `info.context` holds data during the connection."""

    # Store ids of `info.context.scope` objects to check them later.
    run_log: List[bool] = []

    print("Setup GraphQL backend and initialize GraphQL client.")

    # pylint: disable=no-self-use
    class Query(graphene.ObjectType):
        """Root GraphQL query."""

        ok = graphene.Boolean()

        def resolve_ok(self, info):
            """Store `info.context.scope` id."""

            run_log.append("fortytwo" in info.context)
            if "fortytwo" in info.context:
                assert info.context.fortytwo == 42, "Context has delivered wrong data!"
            info.context.fortytwo = 42

            return True

    for _ in range(2):
        print("Make connection and perform query and close connection.")
        client = gql(query=Query, consumer_attrs={"strict_ordering": True})
        await client.connect_and_init()
        for _ in range(2):
            await client.send(msg_type="start", payload={"query": "{ ok }"})
            await client.receive(assert_type="data")
            await client.receive(assert_type="complete")
        await client.finalize()

    # Expected run log: [False, True, False, True].
    assert run_log[2] is False, "Context preserved between connections!"
    assert run_log[0:2] == [False, True], "Context is not preserved in a connection!"
    assert run_log[2:4] == [False, True], "Context is not preserved in a connection!" 
Example #23
Source File: test_field_converter.py    From graphene-django with MIT License 5 votes vote down vote up
def test_should_boolean_convert_boolean():
    assert_conversion(serializers.BooleanField, graphene.Boolean) 
Example #24
Source File: converter.py    From graphene-django with MIT License 5 votes vote down vote up
def convert_form_field_to_nullboolean(field):
    return Boolean(description=field.help_text) 
Example #25
Source File: converter.py    From graphene-django with MIT License 5 votes vote down vote up
def convert_form_field_to_boolean(field):
    return Boolean(description=field.help_text, required=field.required) 
Example #26
Source File: test_converter.py    From graphene-mongo with MIT License 5 votes vote down vote up
def test_should_boolean_convert_boolean():
    assert_conversion(mongoengine.BooleanField, graphene.Boolean) 
Example #27
Source File: converter.py    From graphene-mongo with MIT License 5 votes vote down vote up
def convert_field_to_boolean(field, registry=None):
    return graphene.Boolean(
        description=get_field_description(field, registry), required=field.required
    ) 
Example #28
Source File: test_converter.py    From graphene-django with MIT License 5 votes vote down vote up
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 #29
Source File: test_converter.py    From graphene-sqlalchemy with MIT License 5 votes vote down vote up
def test_should_boolean_convert_boolean():
    assert get_field(types.Boolean()).type == graphene.Boolean 
Example #30
Source File: test_filter_set.py    From graphene-sqlalchemy-filter with MIT License 5 votes vote down vote up
def test_custom_filter_field_type():
    filter_fields = deepcopy(UserFilter._meta.fields)

    assert 'is_admin' in filter_fields
    is_rich = filter_fields['is_admin']
    assert isinstance(is_rich, graphene.InputField)
    assert is_rich.type is graphene.Boolean
    del filter_fields['is_admin']