relayStylePagination()我已经根据apollo文档(https://www.apollographql.com/docs/react/pagination/cursor-based/#relay-style-cursor-pagination)通过以下方式实现:
索引.js:
const httpLink=new HttpLink({
uri:'https://api.github.com/graphql',
headers:{
authorization: 'Bearer -'
}
})
const cache = new InMemoryCache({
typePolicies: {
Query: {
fields: {
repositories:relayStylePagination()
},
},
},
});
const client=new ApolloClient({
link:httpLink,
cache
})
ReactDOM.render(
<ApolloProvider client={client}>
<React.StrictMode>
<App />
</React.StrictMode>
</ApolloProvider>,
document.getElementById('root')
);
Run Code Online (Sandbox Code Playgroud)
应用程序.js:
const App=()=> {
const {loading,error,data,fetchMore}=useQuery(GET_REPOSITORIES_OF_CURRENT_USER,{
variables:{login:"rwieruch"}
})
if (loading) return <h1>Loading...</h1>
if (error) return <p>Error...</p>
console.log(data.user.repositories.edges)
console.log(data)
const pageInfo=data.user.repositories.pageInfo
console.log(pageInfo)
return(
<div>
<RepositoryList repositories={data.user.repositories} onLoadMore={()=>
{return fetchMore({
variables:{
after: data.user.repositories.pageInfo.endCursor,
}
})} …Run Code Online (Sandbox Code Playgroud) 我正在尝试实现 signInWithRedirect() 函数,但是 - 奇怪的是,它不起作用。在下面的代码中,Check 2永远Check 3不会被记录 - 并且不会引发错误:
const signInWithGoogle = async () => {
try {
console.log("Check 1")
await signInWithRedirect(auth, googleAuthprovider);
console.log("Check 2")
const result = await getRedirectResult(auth);
console.log("Check 3");
if (result) {
console.log(result.user);
}
} catch (e) {
console.log(e.message.slice(10));
}
};
Run Code Online (Sandbox Code Playgroud)
另外,如果我使用完全相同的 Google 帐户通过 signInWithPopup() 方法登录,一切都会按预期进行:
const signInWithGoogle = async () => {
const result = await signInWithPopup(auth, googleAuthprovider)
const user = result.user;
console.log(user)
};
Run Code Online (Sandbox Code Playgroud)
我真的很感激一些帮助。谢谢!