2017-10-25 6 views
0

PythonでGraphQLを使用していますが、リストデータを解決しようとしていますが、フィールドはnullを解決しています。実際のリストデータを返すにはどうしたらいいですか?ここで Graphene Pythonリストはすべてのフィールドでnullを解決します

は、ここに私の現在のクエリ query

、望ましくない応答であるスニペットは缶がgraphene playground

でテストされ

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': 
       '[email protected]', 'teamId': 0}, {'id': 39331, 
       'username': 'AHohmann','email': '[email protected]', 
       'teamId': 0}] 
     return resp 

schema = graphene.Schema(query=Query) 

私のコードの抜粋である graphQL response

答えて

3

あなたはjのものではなく、Userのオブジェクトを返す必要がありますust辞書:

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='[email protected]')] 
     return resp 

schema = graphene.Schema(query=Query) 

playgroundをチェックインできます。

関連する問題