问题描述
我正在使用 NodeJS 学习 GraphQL,但出现错误。 我已经开发了一个 mongoDB 和 NodeJS GraphQL REST API 用于理解和学习目的
这是我的代码:
const graphql = require('graphql');
const user = require('../models/User');
const post = require('../models/Post');
const { GraphQLObjectType,GraphQLID,GraphQLString } = graphql;
const UserType = new GraphQLObjectType({
name: 'User',fields: () => ({
id: { type: GraphQLID },fname: { type: GraphQLString },lname: { type: GraphQLString },email: { type: GraphQLString },posts: {
type: PostType,resolve(parent,args) {
return 1;
}
}
})
});
const PostType = new GraphQLObjectType({
name: 'Post',Userid: { type: GraphQLID },title: { type: GraphQLString },date: { type: GraphQLString },})
});
const RootQueryType = new GraphQLObjectType({
name: 'RootQueryType',fields: {
user: {
type: UserType,args: { id: { type: GraphQLID } },args) {
return user.findById({ id: args.id });
}
},post: {
type: PostType,args) {
return post.findById({ id: args.id });
}
}
}
});
module.exports = new graphql.GraphQLSchema({
query: RootQueryType,});
请帮助我找到解决方案。 回答我以解决此错误。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)