GraphQL新手,获取此错误,错误:Show.resolve字段配置必须是对象

GraphQL新手,获取此错误,错误:Show.resolve字段配置必须是对象,graphql,Graphql,这是我的schema.js文件。我遵循了一个教程,所以不确定哪里出了问题。感谢您的帮助,谢谢!这是终端中的错误消息: 错误:Show.resolve字段配置必须是对象 我也不确定我是否出错了,因为我是GraphQL新手 const graphql = require('graphql') const _ = require('lodash') const Show = require('../models/show') const { GraphQLObjectType, GraphQLStri

这是我的schema.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()
            }
        }
    }
})

因为您无法将解析函数放入子对象中


在我的示例中,“Autherschema”是另一个模式,我在父模式中调用auther,但您忽略了这一点。

解析器函数应该与特定字段相关联。查看
Show
的字段——看起来正确吗?与其他类型的字段配置相比,该字段配置有什么不同之处(除了它是函数这一事实——这一部分很好)。我不确定你的意思丹尼尔·里尔登,你能详细说明一下吗?谢谢。我在ShowType中取出了resolve函数,不确定这是否是正确的修复,但它现在正在工作。类型不能有解析程序——只有字段有解析程序。
var bookschema = new GraphQLObjectType({
    name : 'book',
    fields : ( ) => ({
        name : {type : GraphQLString},
        genre : {type : GraphQLString},
        id : {type : GraphQLID },
        auther : {
            type : Autherschema,//it is a another schema.
            resolve(parent,args)
            {
                return _.find(Authers,{id : parent.autherid})
            }
        }
    })
});