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と私が間違ってやっているかを把握することはできません。
完璧!ありがとうございました! – Fluidbyte