Я новичок в graphql и пытаюсь реализовать простое решение helloworld, которое при запросе возвращает null. Установка включает в себя sequelize и pg и pg-hstore, которые я, однако, отключил, чтобы попытаться выяснить, в чем проблема. Заранее спасибо, застрял на два дня.
Вот мой распознаватель:
module.exports = {
Query: {
hello: (parent, { name }, context, info) => {
return `Hello ${name}`;
},
},
};
Вот моя схема:
const { buildSchema } = require("graphql");
module.exports = buildSchema(
`type Query{
hello(name:String!):String!
}
`
);
Вот root моего приложения, приложение. js. Я упустил промежуточное программное обеспечение, которое я отключил, поскольку оно кажется несущественным, поскольку у меня возникает ошибка с или без них
const createError = require("http-errors");
const express = require("express");
const path = require("path");
const cookieParser = require("cookie-parser");
const logger = require("morgan");
const sassMiddleware = require("node-sass-middleware");
const graphqlHTTP = require("express-graphql");
const schema = require("./persistence/graphql/schema");
const persistence = require("./persistence/sequelize/models");
const rootValue = require("./persistence/sequelize/resolvers/index");
const indexRouter = require("./routes/index");
const usersRouter = require("./routes/users");
const app = express();
// view engine setup
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "pug");
app.use(
"/api/graphql",
graphqlHTTP({
schema,
rootValue,
graphiql: true,
})
);
module.exports = app;
, когда я запрашиваю следующее:
{
hello(name: "me")
}
Я получаю эту ошибку:
{
"errors": [
{
"message": "Cannot return null for non-nullable field Query.hello.",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"hello"
]
}
],
"data": null
}
Я знаю, что есть другие серверы, но мне действительно нужно выяснить это с помощью express -graphql. Заранее спасибо.