为什么我收到错误 "Must provide query string." express-graphql?

Why I'm getting the error "Must provide query string." express-graphql?

我从 Express 上的 graphql 开始。当我访问它的路由时出现错误 "Must provide query string."。

这是一个快捷应用。这是我的 app.js

var createError   = require('http-errors');  
var express       = require('express');  
var path          = require('path');  
var cookieParser  = require('cookie-parser');  
var logger        = require('morgan');  
let bodyParser    = require('body-parser');  
var cors          = require('cors');  
    
const graphqlHTTP = require('express-graphql');  
const MySchema    = require('./schema/schema');  

app.use(cors());
app.use(logger('dev'));
app.use(bodyParser.urlencoded({extended: true}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/graphql', graphqlHTTP({
  schema: MySchema,
  graphiql: true,
}));

我的 shema 是:

const graphql = require('graphql');
const {
    GraphQLObjectType, 
    GraphQLString, 
    GraphQLSchema,
    GraphQLList
} = graphql;


//MODELS FROM MONGOOSE
const Entidad = require('../models/entidad');


//TYPES GRAPHQL
const EntidadType = new GraphQLObjectType({
    name: 'Entidad',
    fields : () => ({
        id      : {type : GraphQLString},
        nombre  : {type : GraphQLString},
        created_at : { type : GraphQLString},
        updated_at : { type : GraphQLString},
    })
});

//ROOT QUERY
const RootQuery = new GraphQLObjectType({
    name : 'RootQueryType',
    fields : {
        entidad : {
            type: EntidadType,
            args: {id:{type: GraphQLString}},
            resolve(parent, args){
                //code to get data from db
                return Entidad.findById(args.id);
            }
        }
    }
});

module.exports = new GraphQLSchema({
    query: RootQuery
});

我不知道为什么我在打开 graphiql 时遇到错误。

我测试了其他示例并给出了相同的错误,也许我错过了某些部分....

有什么想法吗?

好吧,我评论了 body-parser 行并解决了问题,另一个问题是因为我没有 rootValue 到 graphql 的路由中。我测试了查询,一切正常。谢谢。