微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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, **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'

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐