I am getting this error when I start the server
Error: Expected undefined to be a GraphQL type.
UPDATE: I believe this has to do with javascript requiring each other. What is the best way to solve this?
I have an account type in file 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...
And my channel type is in 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)
}
})
});
The code with the issue is in my channelTypes.js file. the accountType is coming over as undefined for some reason. I am using module.exports to export accountType and channelType in the respective files. The account works perfectly fine when i comment out the accountType code in the channel file. I am trying to be able to get the channel from account or all accounts associated with a channel but currently only the channel from account side works.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…