如何解决使用graphql和简单的express nodejs设置导致错误和错误
通过遵循本教程,我将构建一个简单的graphql express设置: https://blog.bitsrc.io/how-to-build-a-note-taking-app-with-graphql-and-react-part-1-of-2-febf1aeda091
但是会出现一些错误:
我的文件是::
schema.js
for (var responses of allcomm) {
// insert a parent comment div with values here
for (var comment of comment) {
// insert a new ul div then the comment div here
if (comment.responses.length !== 0) {
}
}
}
resolvers.js
const { makeExecutableSchema } = require('graphql-tools');
const { resolvers } = require('./resolvers');
const typeDefs = `
type Note {
_id: ID!
title: String!,date: Date,content: String!
}
scalar Date
type Query {
allNotes: [Note]
}`;
exports.schema = makeExecutableSchema({
typeDefs,resolvers
});
models / note.js
const Note = require("./models/note");
exports.resolvers = {
Query : {
async allNotes(){
return await Note.find();
}
}
};
app.js
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const NoteSchema = new Schema({
title : {
type: String,required: true
},content: {
type: String,date: {
type: Date,default: Date.now
}
});
exports.Note = mongoose.model('Note',NoteSchema);
================================================ ==========
一切都很好,但是仍然出现“ TypeError:graphlHTTP不是函数”错误。 我附上了屏幕截图。请提出解决方法。
解决方法
我认为您在app.js中有错字。您需要导入graphqlHTTP而不是graphlHTTP并使用它。
const {graphqlHTTP} = require(“ express-graphql”);
这是npm pacakge链接。 Spring Data R2DBC
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。