【发布时间】:2018-11-13 02:52:58
【问题描述】:
我在启动服务器时收到此错误
错误:预期未定义为 GraphQL 类型。
更新:我相信这与 javascript 相互要求有关。解决这个问题的最佳方法是什么?
我在文件 accountTypes.js 中有一个帐户类型
const { channelType } = require('../channel/channelTypes');
//Define Order type
const accountType = new GraphQLObjectType({
name: 'Account',
description: 'An account',
fields: () => ({
id: {
type: new GraphQLNonNull(GraphQLInt),
description: 'The id of the account.'
},
name: {
type: new GraphQLNonNull(GraphQLString),
description: 'Name of the account.'
},
channel: {
type: channelType,
resolve: resolver(db.Account.Channel),
description: 'Channel'
},
etc...
我的频道类型在 channelTypes.js 中
const { accountType } = require('../account/accountTypes');
// Define Channel type
const channelType = new GraphQLObjectType({
name: 'Channel',
description: 'A Channel',
fields: () => ({
id: {
type: new GraphQLNonNull(GraphQLInt),
description: 'ID of the channel.'
},
name: {
type: new GraphQLNonNull(GraphQLString),
description: 'Name of the channel',
deprecationReason: 'We split up the name into two'
},
accounts: {
type: new GraphQLList(accountType),
description: 'accounts associated with this channel',
resolve: resolver(db.Channel.Account)
}
})
});
有问题的代码在我的 channelTypes.js 文件中。由于某种原因,accountType 以未定义的形式出现。我正在使用 module.exports 在各自的文件中导出 accountType 和 channelType。当我注释掉频道文件中的 accountType 代码时,该帐户可以正常工作。我正在尝试能够从帐户或与频道关联的所有帐户获取频道,但目前只有来自帐户端的频道有效。
【问题讨论】:
标签: node.js sequelize.js graphql