Это моя схема. js файл. Я следовал учебному пособию, поэтому не уверен, где я ошибся. Любая помощь приветствуется, спасибо! Это сообщение об ошибке в терминале:
Ошибка: Конфигурация поля Show.resolve должна быть объектом
Опять не уверен, что я ошибся, поскольку я новичок в GraphQL.
const graphql = require('graphql')
const _ = require('lodash')
const Show = require('../models/show')
const { GraphQLObjectType, GraphQLString, GraphQLSchema, GraphQLID, GraphQLInt, GraphQLList } =
graphql
const ShowType = new GraphQLObjectType({
name: 'Show',
fields: () => ({
id: { type: GraphQLID },
name: { type: GraphQLString },
genre: { type: GraphQLString },
year: { type: GraphQLInt },
poster: { type: GraphQLString },
resolve(parent, args) {
// return _.find(users, { id: parent.userId } )
return Show.findById(args.id)
}
})
})
const RootQuery = new GraphQLObjectType({
name: 'RootQueryType',
fields: {
show: {
type: ShowType,
args: { id: { type: GraphQLID } },
resolve(parent, args) {
return Show.findById(args.id)
}
},
shows: {
type: new GraphQLList(ShowType),
resolve(parent, args) {
// return shows
return Show.find({})
}
}
}
})
const Mutation = new GraphQLObjectType({
name: 'Mutation',
fields: {
addShow: {
type: ShowType,
args: {
name: { type: GraphQLString },
genre: { type: GraphQLString },
year: { type: GraphQLInt },
poster: { type: GraphQLString },
},
resolve(parent, args) {
let show = new Show({
name: args.name,
genre: args.genre,
year: args.year,
poster: args.poster,
})
return show.save()
}
}
}
})