我用的是“反应--阿波罗”和“图形to标签”,但有些东西似乎失败了。服务器运行在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"}我也试图通过邮递员运行这个有效载荷,它看起来很好。
这是我的阿波罗客户端配置:
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 || {})
});发布于 2019-01-15 12:04:16
多亏了@azium,我弄明白了。再次谢谢你。Content-Type正在复制自己:
Request Headers -> content-type: application/json, application/json
因此,删除headers对象可以解决这个问题。
function create (initialState) {
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' <-- remove the duplicate
//}
}),
cache: new InMemoryCache().restore(initialState || {})
});
}https://stackoverflow.com/questions/54192070
复制相似问题