簡體   English   中英

為什么會出現錯誤“必須提供查詢字符串”。express-graphql?

[英]Why I'm getting the error “Must provide query string.” express-graphql?

我從Expressq上的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, })); 

我的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解析器這一行,並解決了這個問題,另一個問題是因為我在graphql的路由中沒有rootValue。 我測試了查詢,一切正常。 謝謝。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM