微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

GraphQL NodeJS 错误:提供的用于构建架构的类型之一缺少名称

如何解决GraphQL NodeJS 错误:提供的用于构建架构的类型之一缺少名称

我正在使用 NodeJS 学习 GraphQL,但出现错误。 我已经开发了一个 mongoDB 和 NodeJS GraphQL REST API 用于理解和学习目的

enter image description here

这是我的代码

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 举报,一经查实,本站将立刻删除。