【发布时间】:2018-04-14 01:55:33
【问题描述】:
我是 GraphQL 新手,并试图针对一个模拟数据源进行基本查询设置,该数据源只是用 filter 解决了一个通过 id 提取记录的承诺。我有以下内容:
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,但不知道我做错了什么。
【问题讨论】: