小编Jor*_*ley的帖子

如何在firebase中查询给定键的多个值

我试图在方法中使用'OR' ||语句equalTo(),但这似乎不起作用.我是否必须为每个值单独调用,或者是否有办法在firebase中进行条件查询?

export const startSetContent = () => {
  return (dispatch, getState) => {
    const ref = database.ref("content");
    return ref
      .orderByChild("category")
      .equalTo('one-act-play' || 'ten-min-play' || 'full-length-play')
      .once('value')
      .then(snapshot => {
        const content = [];
        snapshot.forEach(childSnapshot => {
          content.push({
            id: childSnapshot.key,
            ...childSnapshot.val()
          });
        });
        dispatch(setContent(content));
      });
  };
}; 
Run Code Online (Sandbox Code Playgroud)

javascript firebase firebase-realtime-database

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

Apollo Link中间件未向请求添加自定义标头

我正在尝试通过Apollo中间件将身份验证令牌添加到我的所有http请求中。看来我的中间件从未被解雇。我正在从本地主机:8080上的客户端访问本地主机:8081上的服务器。我是Apollo的新手,所以我可能对ApolloLink有误解。

const httpLink = new HttpLink({ uri: 'http://localhost:8081/graphql' });

const getTokenMiddleware = new ApolloLink((operation, forward) => {
  operation.setContext(({ headers }) => ({
    headers: {
      ...headers,
      'x-token': localStorage.getItem('token') || null,
      'x-refresh-token': localStorage.getItem('refreshToken') || null,
    },
  }));

  return forward(operation);
});

const client = new ApolloClient({
  cache: new InMemoryCache(),
  link: from([
    getTokenMiddleware,
    httpLink
  ]),
  uri: 'http://localhost:8081/graphql',
});
Run Code Online (Sandbox Code Playgroud)

这是我在服务器上获得的标头

headers: { 
     host: 'localhost:8081',
     connection: 'keep-alive',
     'content-length': '351',
     accept: '*/*',
     origin: 'http://localhost:8080',
     'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 …
Run Code Online (Sandbox Code Playgroud)

http apollo react-apollo

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

如何在 IntelliJ 中自动添加分号

当我忘记;声明或函数末尾的 a时,IntelliJ 总是让我知道。有没有办法让它在看到我错过了一个时自动添加一个?

intellij-idea

4
推荐指数
1
解决办法
1713
查看次数

Babel 在运行 Jest 时不会编译 .test.js 文件

在运行 yarn run jest --no-cache 时,会抛出一个错误:

SyntaxError: Unexpected token import
Run Code Online (Sandbox Code Playgroud)

我最好的猜测是 babel 没有到达这个测试文件。我需要将它们包含在 .babelrc 中吗?

小路:

/src/tests/LandingPage.test.js
Run Code Online (Sandbox Code Playgroud)

测试文件:

import React from 'react';
import ReactShallowRenderer from 'react-test-renderer/shallow';
import LandingPage from '../../components/LandingPage';

test('Should render LandingPage correctly', () => {
  const renderer = new ReactShallowRenderer();
  renderer.render(<LandingPage />);
  expect(renderer.getRenderOutput()).toMatchSnapshot();
});
Run Code Online (Sandbox Code Playgroud)

.babelrc :

{
  "presets": [
    "env",
    "react"
  ],
  "plugins": [
    "transform-class-properties",
    "transform-object-rest-spread"
  ]
}
Run Code Online (Sandbox Code Playgroud)

testing reactjs jestjs babeljs

3
推荐指数
1
解决办法
4065
查看次数