2017-11-01 16 views
0

私はGraphQLを初めて使用していて、idでレコードをプルするために約束を解決するモックデータソースに対して基本クエリ設定を取得しようとしています(filter)。私は、次のしている:GraphQL Query.resolveはオブジェクトでなければなりません

const { 
    GraphQLSchema, 
    GraphQLObjectType, 
    GraphQLString, 
    GraphQLList 
} = require('graphql') 

const db = require('../db') 

const getUserById = (id) => db.read(id) 

const UserType = new GraphQLObjectType({ 
    name: 'User', 
    description: 'User Type', 
    fields:() => ({ 
    first_name: { 
     type: GraphQLString 
    }, 
    last_name: { 
     type: GraphQLString 
    }, 
    email: { 
     type: GraphQLString 
    }, 
    friends: { 
     type: new GraphQLList(UserType), 
     resolve: (user) => user.friends.map(getUserById) 
    } 
    }) 
}) 

const QueryType = new GraphQLObjectType({ 
    name: 'Query', 
    description: 'User Query', 
    fields:() => ({ 
    user: { 
     type: UserType, 
     args: { 
     id: { type: GraphQLString } 
     } 
    }, 
    resolve: (root, args) => getUserById(args.id) 
    }) 
}) 

const schema = new GraphQLSchema({ 
    query: QueryType 
}) 


module.exports = schema 

私はgraphQLHTTPでこれを実行しようとすると、私は、次を得る:

Error: Query.resolve field config must be an object 

私は、次のしてきたZero to GraphQL in 30 Minutesと私が間違ってやっているかを把握することはできません。

答えて

1

クエリタイプのフィールドの1つであるuserのクエリに対して、誤ってリゾルバを作成しました。 userフィールドの中に移動してください。

+0

完璧!ありがとうございました! – Fluidbyte

関連する問題