简体   繁体   English

为什么会出现错误“必须提供查询字符串”。express-graphql?

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

I'm beginning with graphql on express. 我从Expressq上的graphql开始。 I'm getting the error "Must provide query string." 我收到错误消息“必须提供查询字符串”。 when I access to the route for it. 当我访问它的路线时。

It's an express app. 这是一个快递应用。 Here is my app.js 这是我的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, })); 

And my shema is: 我的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 }); 

I don't know why I'm getting the error when open graphiql. 我不知道为什么在打开graphiql时出现错误。

I test other examples and give me the same error, maybe there is some part that I missed.... 我测试了其他示例,并给了我相同的错误,也许有些地方我错过了...。

Some idea? 有想法吗

Well, I commented the line of body-parser and I fix the problem, the other problem is because I don't have a rootValue into the route of graphql. 好吧,我评论了body解析器这一行,并解决了这个问题,另一个问题是因为我在graphql的路由中没有rootValue。 I tested the queries and it's all ok. 我测试了查询,一切正常。 Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GraphQL 文件上传纯 JS “必须提供查询字符串。” - GraphQL file upload plain JS "Must provide query string." Apollo Server,Graphql-必须提供查询字符串 - Apollo Server, Graphql - Must provide query string 错误:正文必须是字符串。 收到:{ resolvers: [[function HelloResolver]], validate: false } 使用 Type-graphql 和 apollo-server-express 时 - Error: Body must be a string. Received: { resolvers: [[function HelloResolver]], validate: false } when using Type-graphql and apollo-server-express Express-GraphQL 上的多个过滤器 - Multiple Filters On Express-GraphQL GraphQL:错误:必须提供文档 - GraphQL: Error: Must provide Document 在 Express GraphQL 中出错:架构必须包含唯一命名的类型,但包含多个名为“String”的类型 - Getting error in Express GraphQL: Schema must contain uniquely named types but contains multiple types named "String" express-graphql-匹配父路由的子路由 - express-graphql - subroutes matching parent route 如何使用 express-graphql 抛出多个错误? - How to throw multiple errors with express-graphql? 使用 graphql-sequelize 解析器(Node.js、express-graphql)限制递归 GraphQL 模式查询的深度 - Limit Depth on Recursive GraphQL Schema Query using graphql-sequelize resolver (Node.js, express-graphql) Lstat:类型错误:路径必须是字符串。 - Lstat: Type error: path must be a string.
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM