我require
在我的模型的一个具体型号,我得到Error: Offer.user field type must be Output Type but got: [object Object].
对复杂对象获取的字段类型错误graphql
优惠:
var graphql = require('graphql'),
GraphQLBoolean = graphql.GraphQLBoolean,
GraphQLObjectType = graphql.GraphQLObjectType,
GraphQLInt = graphql.GraphQLInt,
GraphQLString = graphql.GraphQLString;
var Game = require('./game');
var Post = require('./post');
var User = require('./user');
var Offer = new GraphQLObjectType({
name: 'Offer',
description: 'This object represents the offers for the specified user.',
fields:() => ({
id: {
description: 'The id of the offer.',
type: GraphQLInt
},
createdAt: {
description: 'The creation date of the offer.',
type: GraphQLString
},
exchange: {
description: 'Specifies whether this offer is exchangeable.',
type: GraphQLBoolean
},
price: {
description: 'The price for the specified offer.',
type: GraphQLInt
},
game: {
description: 'The corresponding game of the offer.',
type: Game,
resolve: offer => offer.getGame()
},
post: {
description: 'The corresponding post which expand this offer.',
type: Post,
resolve: offer => offer.getPost()
},
user: {
description: 'The user who created this offer.',
type: User,
resolve: offer => offer.getUser()
}
})
});
module.exports = Offer;
用户:
var graphql = require('graphql'),
GraphQLString = graphql.GraphQLString,
GraphQLObjectType = graphql.GraphQLObjectType,
GraphQLList = graphql.GraphQLList;
var Offer = require('./offer');
var Request = require('./request');
var Comment = require('./comment');
var User = new GraphQLObjectType({
name: 'User',
description: 'This object represents the registered users.',
fields:() => ({
id: {
description: 'The id of the user.',
type: GraphQLString
},
name: {
description: 'The full name of the user.',
type: GraphQLString
},
email: {
description: 'The email of the user.',
type: GraphQLString
},
phone: {
description: 'The phone number of the user.',
type: GraphQLString
},
createdAt: {
description: 'The creation date of the user.',
type: GraphQLString
},
offers: {
description: 'The offers created by the user.',
type: new GraphQLList(Offer),
resolve: user => user.getOffers()
},
requests: {
description: 'The requests created by the user.',
type: new GraphQLList(Request),
resolve: user => user.getRequests()
},
comments: {
description: 'The comments this users wrote.',
type: new GraphQLList(Comment),
resolve: user => user.getComments()
}
})
});
module.exports = User;
当我从User
架构删除offers
,requests
和comments
字段,它正在工作。
我试过要求在User
中定义的所有依赖关系,但我仍然得到相同的错误。
我错过了什么?
注意:如果您使用ES6模块,则无法使用该语法覆盖Module Export对象,因此无法解决此问题。 –
它实际上将错误移到了'index.js'文件(查询对象被定义的地方)。我想我会转向ES6。谢谢! – itaied
更新:ES6做到了。 – itaied