我正在遵循教程并尝试启动节点服务器,但我无法将其导入 Apollo 包中的函数
const {graphqlExpress, graphiqlExpress} = require('apollo-server-express'); // here i importing fucntions
const bodyParser = require('body-parser'); // import parser
const cors = require('cors'); // import cors
const express = require('express'); // import cors
const { makeExecutableSchema } = require('graphql-tools');
const port = 9000; // define port
const schema = makeExecutableSchema({typeDefs, resolvers}); // init shcema
const app = express();
app.use(cors(), bodyParser.json());
app.use('/graphql', graphqlExpress({schema})); // is not a function
app.use('/graphiql', graphiqlExpress({endpointUrl: '/graphql'})); // is not a function
app.listen(port, () => console.log(`Server …Run Code Online (Sandbox Code Playgroud) 我有公共和受保护的路由,它们按以下逻辑实现
useEffect(() => {
checkIfAuthenticated(); //This function checks if the token is in localStorage
// Initial state isAuthenticated = false
}, []);
const newHistory = useHistory()
<Router history={newHistory}>
{isAuthenticated ? (
<Layout>
<Switch>
<Route
exact
path="/clients"
component={Clients}
/>
<Route
exact
path="/staff"
component={Staff}
/>
<Redirect to="/clients" />
</Switch>
</Layout>
) : (
<>
<Route path="/login" component={Login} />
<Redirect to="/login" />
</>)}
</Router>
//store
checkIfAuthenticated() {
const accessToken = localStorage.getItem("access_token");
const refreshToken = localStorage.getItem("refresh_token");
if (accessToken && refreshToken) {
this.isAuthenticated = true; …Run Code Online (Sandbox Code Playgroud)