【发布时间】:2019-06-09 01:32:45
【问题描述】:
我正在使用 react-apollo 和 graphql-tag 但似乎有些失败。服务器在 express 和 postgraphile 上运行。
我做错了吗?
邮递员(工作):
{
"query": "{\n allPosts(first:10) {\n nodes {\n \tnodeId,\n id,\n content\n }\n }\n}"
}
反应(失败);
Status Code: 400 Bad Request
Response: {"errors":[{"message":"Must provide a query string."}]}
代码:
export const allPostsQuery = gql`
{
allPosts(first: 10) {
nodes {
nodeId,
id,
content
}
}
}
`;
. . .
<Query query={ allPostsQuery }> . . . </Query>
生成的请求负载看起来是这样的:
{"operationName":null,"variables":{},"query":"{\n allPosts(first: 10) {\n nodes {\n nodeId\n id\n content\n __typename\n }\n __typename\n }\n}\n"}
我也尝试通过 Postman 运行这个有效载荷,它看起来还不错。
这是我的 Apollo 客户端配置:
return new ApolloClient({
connectToDevTools: process.browser,
ssrMode: !process.browser,
link: new HttpLink({
uri: 'http://127.0.0.1:8181/graphql',
credentials: 'include',
headers: {
'Content-Type': 'application/json'
}
}),
cache: new InMemoryCache().restore(initialState || {})
});
【问题讨论】:
-
对我来说似乎是 mime 类型/标题不匹配。您可以记录标题,特别是邮递员和反应请求的
content-type吗? (从你的graphql端点内的服务器) -
谢谢,帮了大忙
标签: node.js express graphql react-apollo postgraphile