javascript - GraphQL NodeJS 错误:提供的用于构建模式的类型之一缺少名称
问题描述
我正在使用 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',
fields: () => ({
id: { type: GraphQLID },
Userid: { type: GraphQLID },
title: { type: GraphQLString },
date: { type: GraphQLString },
})
});
const RootQueryType = new GraphQLObjectType({
name: 'RootQueryType',
fields: {
user: {
type: UserType,
args: { id: { type: GraphQLID } },
resolve(parent, args) {
return user.findById({ id: args.id });
}
},
post: {
type: PostType,
args: { id: { type: GraphQLID } },
resolve(parent, args) {
return post.findById({ id: args.id });
}
}
}
});
module.exports = new graphql.GraphQLSchema({
query: RootQueryType,
});
请帮助我找到解决方案。回答我以解决此错误。
解决方案
推荐阅读
- python - driver.find_element_by_xpath - 试图检索文本
- python - 有没有更简单的方法来进行随机测验?
- rust - 如何发出 GET 请求并打印结果?
- linux - 我试图在 azure data studio 中运行 sql 代码,但出现操作系统错误 5(拒绝访问)MSG 5123 Level 16
- java - 使用 jndi 的 spring jms 客户端无法与 weblogic 连接
- javascript - Javascript:重新分配的变量正在变异
- sql - 没有更多数据可以从套接字 IO 读取错误:软件导致连接中止:套接字写入错误 Oracle
- javascript - Typescript React Native AnimatedEvent:'类型'编号'不可分配给类型'映射'.ts(2322)'
- google-apps-script - 应用脚本中输入字符串的 setFontColor
- kotlin - Kotlin 空值检查编译器合约如何工作?