Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Graphene Python列出所有字段的解析空值_Python_Graphql_Graphene Python - Fatal编程技术网

Graphene Python列出所有字段的解析空值

Graphene Python列出所有字段的解析空值,python,graphql,graphene-python,Python,Graphql,Graphene Python,我正在python中使用GraphQL,我试图解析列表数据,但字段解析为null。如何让他们返回实际的列表数据 下面是我的代码片段 import graphene class User(graphene.ObjectType): """ Type definition for User """ id = graphene.Int() username = graphene.String() email = graphene.String() class Qu

我正在python中使用GraphQL,我试图解析列表数据,但字段解析为null。如何让他们返回实际的列表数据

下面是我的代码片段

import graphene


class User(graphene.ObjectType):
    """ Type definition for User """
    id = graphene.Int()
    username = graphene.String()
    email = graphene.String()

class Query(graphene.ObjectType):
    users = graphene.List(User)

    def resolve_users(self, args):
        resp = [{'id': 39330, 'username': 'RCraig', 'email': 
                 'WRussell@dolor.gov', 'teamId': 0}, {'id': 39331, 
                 'username': 'AHohmann','email': 'AMarina@sapien.com', 
                 'teamId': 0}]
        return  resp

schema = graphene.Schema(query=Query)
该代码段可以在以下位置进行测试:

这是我目前的问题

以及不期望的反应

您需要返回用户的对象,而不仅仅是字典:

import graphene


class User(graphene.ObjectType):
    """ Type definition for User """
    id = graphene.Int()
    username = graphene.String()
    email = graphene.String()

class Query(graphene.ObjectType):
    users = graphene.List(User)

    def resolve_users(self, args):
        resp = [User(id=39330, username='RCraig', email='WRussell@dolor.gov')]
        return  resp

schema = graphene.Schema(query=Query)

您可以签入。

此代码只返回一个列表(一组id、用户名、电子邮件)。如何返回多个集合?@jigarshah我知道这已经晚了,但您只需在上面的代码中添加更多的
User
对象到
resp