【发布时间】:2018-11-06 23:21:29
【问题描述】:
我正在运行 apollo-server-express,一切正常。我有 2 个端点 - 1 个用于 graphiql (/graphql) 和一个用于非交互式 (/client) 查询(我知道 - 在我开始使用 apollo 之前它们被称为)。
app.use('/client', bodyParser.json() ,
(req, res,next) => {
const context = { pool , apiKey:req.query.key , bidules };
if (server.isAuthorized(context.apiKey)) {
return graphqlExpress({
schema: schema,
context: context,
tracing: true,
cacheControl: {
defaultMaxAge: 30,
}
}) (req,res,next);
}
else {
res.setHeader('Content-Type', 'application/json');
res.status(403)
.send (JSON.stringify({
errors:[ {message: "api key is unauthorized"} ]
}));
}
}
);
// endpoint for browser graphIQL
app.use('/graphql', graphiqlExpress({
endpointURL: '/client'
}));
app.use("/schema", (req, res) => {
res.set("Content-Type", "text/plain");
res.send(printSchema(schema));
});
但是,当我介绍阿波罗引擎时
engine.listen({
port: port,
expressApp: fidserver.app,
graphqlPaths: ['/graphql', '/client']
});
一切仍然正常 - 除非我在浏览器上刷新 graphiql,并将查询作为浏览器 url 上的参数。
然后我得到这个错误
{"errors":[{"message":"Unsupported Content-Type from origin: text/html"}]}
在没有运行 apollo 引擎的情况下做同样的事情不会导致错误。如果再次运行查询,或者在没有查询和变量参数的情况下刷新浏览器,无论是否启用 Apollo 引擎,一切都可以正常工作。
当错误发生时,我可以从我的服务器日志中看到它正在尝试返回一个包含一些用于从某处解码参数的 javascript 的反应网页,但我无法从哪里追踪 - 它没有达到我的任何代码。
【问题讨论】:
标签: graphql apollo-server