使用graphql和简单的express nodejs设置导致错误和错误

时间:2020-08-14 01:31:56

标签: node.js mongodb graphql

通过遵循本教程,我将构建一个简单的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,
        required: true
    },
    date: {
        type: Date,
        default: Date.now
    }
});
exports.Note = mongoose.model('Note', NoteSchema);

================================================ ==========

一切都很好,但是仍然出现“ TypeError:graphlHTTP不是函数”错误。 我附上了屏幕截图。请提出解决方法。

enter image description here

1 个答案:

答案 0 :(得分:0)

我认为您在app.js中有错字。您需要导入graphqlHTTP而不是graphlHTTP并使用它。

const {graphqlHTTP} = require(“ express-graphql”);

这是npm pacakge链接。 Spring Data R2DBC