Я начинаю с graphql на экспресс.Я получаю сообщение об ошибке «Необходимо указать строку запроса».когда я получаю к нему доступ.
Это экспресс-приложение.Вот мой 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,
}));
И моя шма:
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.
Я тестирую другие примеры и выдаю мне ту же ошибку, возможно, тамкакая-то часть, которую я пропустил ...
Какая-то идея?