is there a way that ApolloClient accepts request from servers with self signed certificates?
import ApolloClient from 'apollo-boost';
const client = new ApolloClient({
uri: `https://${window.location.hostname}:8080/graphql`,
rejectUnauthorized: false
});
Error on a Request: OPTIONS https://localhost:8080/graphql net::ERR_CERT_AUTHORITY_INVALID
While you don't need React or another front-end framework just to fetch data with Apollo Client, our view layer integrations make it easier to bind your queries to your UI and reactively update your components with data.
You can use apollo-link-rest to call REST API inside your GraphQL queries.
Apollo Client uses HttpLink to send GraphQL operations to a server over HTTP. The link supports both POST and GET requests, and it can modify HTTP options on a per-query basis. This comes in handy when implementing authentication, persisted queries, dynamic URIs, and other granular updates.
A fetch policy defines how Apollo Client uses the cache for a particular query. The default policy is cache-first , which means Apollo Client checks the cache to see if the result is present before making a network request. If the result is present, no network request occurs.
Frontend
Apollo client might reject the certificate even if you clicked "I understand the risks" and went to the page. You can workaround this by enabling self signed certificates from local host: on chrome type
chrome://flags/#allow-insecure-localhost
to the navigation and click enable.
Other option is to install the certficate as trusted. More about that in this question.
Backend
If you are using Apollo client in backend with Nodejs you can start the process with:
NODE_TLS_REJECT_UNAUTHORIZED=0
This can be done with e.g. env-cmd package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With