Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apollo-client self signed certificate

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
    });
  • rejectUnauthorized: false doesn´t work

Error on a Request: OPTIONS https://localhost:8080/graphql net::ERR_CERT_AUTHORITY_INVALID

like image 266
Marcel Rösler Avatar asked Apr 11 '18 20:04

Marcel Rösler


People also ask

Does Apollo Client require react?

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.

Can I use Apollo Client with REST API?

You can use apollo-link-rest to call REST API inside your GraphQL queries.

How are HTTP requests sent by Apollo Client authenticated?

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.

Does Apollo Client use Fetch?

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.


1 Answers

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.

like image 133
eemelipa Avatar answered Sep 22 '22 15:09

eemelipa