Search code examples
graphqlcreate-react-appapollo-client

rejectUnauthorized: false not being recognized in ApolloClient


My current setup is:

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')
);

When I useQuery I get createHttpLink.ts:121 POST https://*****.test/wp/graphql net::ERR_CERT_INVALID. From what I can tell this is the current way to use a self-signed certificate but it doesn't seem to work. i can't find any documentation otherwise. What's wrong with my current implementation that seems to be ignoring the reject?


Solution

  • This is not a complete answer but I'm marking this as solved anyway. It has nothing to do with Apollo Client or node-fetch, I was testing this in Chrome(MacOS to be specific) and it's rejecting the self-signed certificate. I'm just continuing my development with Firefox for now as it will accept the certificate. The agent property still shows up as empty in dev tools, so that is perhaps a red herring? Not sure but I can continue for now.