0

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?

pandabrand
  • 397
  • 1
  • 13
  • https://stackoverflow.com/a/58624854/6124657 ? – xadm Oct 13 '20 at 21:47
  • @xadm saw that post before it didn't help, I tried adding `process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;` and still the same error. – pandabrand Oct 14 '20 at 00:09
  • I took a look at the Apollo Provider in React Dev Tools and the agent object in fetch options is empty. So now it seems that what's in my code isn't making it to the browser. Why would my fetch remove it? [Imgur](https://i.imgur.com/PF3F8JY.png) – pandabrand Oct 14 '20 at 00:15

1 Answers1

1

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.

pandabrand
  • 397
  • 1
  • 13