CKD*_*CKD 5 reactjs graphql server-side-rendering react-apollo apollo-client
使用来自我们的 graphql 服务器的数据呈现页面服务器端有错误。
我们的 GraphQL 服务器与多个 API 对话并返回一个由 Apollo UI 处理的 graphQL 响应。
某些 GraphQL 错误不被视为严重错误,我们仍希望使用它来渲染页面。例如
data: {
thing: {
id: "1234"
name: "Thing"
nonCriticalData: null
},
error: {
graphQLErrors: [
path: ['thing', 'nonCriticalData']
]
}
}
Run Code Online (Sandbox Code Playgroud)
根据我们从 Apollo 得到的上述响应,我们仍然希望使用thing. 综观实行getDataFromTree 这里,任何错误都会抛出,没有数据的其余部分。
以下是我们计划如何处理代码的片段:
getDataFromTree(app)
.then(() => {})
.catch(error => {
const content = ReactDOMServer.renderToString(app);
const { data } = client.getInitialState();
console.log("data", data); <-------------- We need data here
console.log("error", error); <———————— errors are here
// render page with data
});
Run Code Online (Sandbox Code Playgroud)
请让我知道是否有办法解决这个问题,或者我是否遗漏了什么。
getDataFromTree甚至应该抛出错误?感觉责任应该在消费者身上。