Python graphene 模块,Argument() 实例源码

我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用graphene.Argument()

项目:graphene-gae    作者:graphql-python    | 项目源码 | 文件源码
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)
项目:graphene-gae    作者:graphql-python    | 项目源码 | 文件源码
def test_reports_argument_validation_errors(self):
        for method in (self.get, self.post):
            response = method('/graphql', expect_errors=True, params=dict(
                query='''
                    query helloYou { greet(who: 123), ...shared }
                    query helloWorld { greet(who: "World"), ...shared }
                    query helloDolly { greet(who: "Dolly"), ...shared }
                    fragment shared on Query {
                        shared: greet(who: "Everyone")
                    }
                ''',
                operation_name='helloYou'
            ))

            self.assertEqual(response.status_int, 400)

            response_dict = json.loads(response.body)
            self.assertEqual(response_dict["errors"][0]["message"], "Argument \"who\" has invalid value 123.\nExpected type \"String\", found 123.")
项目:graphene-django    作者:graphql-python    | 项目源码 | 文件源码
def test_filterset_descriptions():
    class ArticleIdFilter(django_filters.FilterSet):

        class Meta:
            model = Article
            fields = ['id']

        max_time = django_filters.NumberFilter(method='filter_max_time', label="The maximum time")

    field = DjangoFilterConnectionField(ArticleNode, filterset_class=ArticleIdFilter)
    max_time = field.args['max_time']
    assert isinstance(max_time, Argument)
    assert max_time.type == Float
    assert max_time.description == 'The maximum time'