小编Sas*_*ria的帖子

无法从 apollo-server-express 获取函数

我正在遵循教程并尝试启动节点服务器,但我无法将其导入 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)

javascript express graphql

12
推荐指数
1
解决办法
6911
查看次数

刷新页面后如何保持在受保护的路线上。反应路由器 5.2.0

我有公共和受保护的路由,它们按以下逻辑实现

   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)

javascript reactjs react-router-dom

5
推荐指数
1
解决办法
1439
查看次数

标签 统计

javascript ×2

express ×1

graphql ×1

react-router-dom ×1

reactjs ×1