rejectUnauthorized:在ApolloClient中无法识别为false

时间:2020-10-13 20:53:08

标签: graphql create-react-app apollo-client

我当前的设置是:

import {
  ApolloClient,
  ApolloProvider,
  gql,
  HttpLink,
} from '@apollo/client';
import fetch from 'node-fetch';
import { Agent } from 'https';
...

const agent = new Agent({
  rejectUnauthorized: false,
});

const httpLink = new HttpLink({
  uri: process.env.REACT_APP_GRAPHQL_URL,
  fetch: fetch,
  fetchOptions: {
    agent: agent
  },
});
...
const client = new ApolloClient({
  link: httpLink,
  cache: cache,
  typeDefs,
  connectToDevTools: true,
});
...
ReactDOM.render(
    <ApolloProvider client={client}>
      <App />
    </ApolloProvider>,
  document.getElementById('root')
);

当我useQuery得到createHttpLink.ts:121 POST https://*****.test/wp/graphql net::ERR_CERT_INVALID时。据我所知,这是使用自签名证书的当前方法,但似乎不起作用。否则我找不到任何文档。我目前的实现似乎忽略了拒绝,这是怎么回事?

1 个答案:

答案 0 :(得分:0)

这不是一个完整的答案,但是我还是将其标记为已解决。它与Apollo Client或node-fetch无关,我在Chrome(具体是MacOS)中进行了测试,并且拒绝了自签名证书。我现在正在继续使用Firefox进行开发,因为它将接受证书。 agent属性在开发工具中仍然显示为空,因此这可能是一个红色鲱鱼吗?不确定,但我可以继续。