Node.js GraphQL/Apollo:“没有可用的模式”。NodeJS
我正在尝试使用GraphQL/Apollo,我的文档资源管理器可以无限加载,没有显示任何内容,我也不能进行任何查询 几分钟后,我收到一个typeError错误,无法获取 这是我的graphql/index.js文件:Node.js GraphQL/Apollo:“没有可用的模式”。NodeJS,node.js,graphql,apollo,graphiql,Node.js,Graphql,Apollo,Graphiql,我正在尝试使用GraphQL/Apollo,我的文档资源管理器可以无限加载,没有显示任何内容,我也不能进行任何查询 几分钟后,我收到一个typeError错误,无法获取 这是我的graphql/index.js文件: 控制台和DevTools都已清除。谁能解释一下,怎么了?谢谢大家! 有点不清楚您试图实现什么,但是您已经在/graphql路由中添加了一个中间件,它什么也不做: app.use('/graphql', () => { }, graphqlExpress({ schema })
控制台和DevTools都已清除。谁能解释一下,怎么了?谢谢大家! 有点不清楚您试图实现什么,但是您已经在/graphql路由中添加了一个中间件,它什么也不做:
app.use('/graphql', () => { }, graphqlExpress({ schema }))
插入的函数会在任何东西到达/graphql路由时被调用,因为您的函数不会调用next或结束响应,所以不会调用下一个中间件graphqlExpress,请求也会挂起
另一个问题是graphqlExpress需要在调用bodyParser中间件之前运行它。这意味着您可以执行以下任一操作:
const bodyParser = require('body-parser')
// Option A -- body parser will run prior to all routes after this point
app.use(bodyParser.json())
// Option B -- body parser will only run for the graphql route
app.use('/graphql', bodyParser.json(), graphqlExpress({ schema }))
如果您没有包括bodyParser,graphqlExpress通常会抱怨并告诉您,只要您一开始就实际到达了它
const bodyParser = require('body-parser')
// Option A -- body parser will run prior to all routes after this point
app.use(bodyParser.json())
// Option B -- body parser will only run for the graphql route
app.use('/graphql', bodyParser.json(), graphqlExpress({ schema }))