Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
565 views
in Technique[技术] by (71.8m points)

graphql - WebSocketLink and self-signed certificates giving net::ERR_CERT_AUTHORITY_INVALID error

I am using apollo graphql to make https-based calls to my graphene backend. Queries and mutations work fine. In trying to add support for graphql subscriptions, I tried modifying my client setup code to include:

// Create a WebSocket link:
const wsLink = new WebSocketLink({
  uri: "wss://" + hostname + "/graphql/",
  options: {
    reconnect: true,
  }
});


const splitLink = split(
  ({ query }) => {
    const definition = getMainDefinition(query);
    return (
      definition.kind === 'OperationDefinition' &&
      definition.operation === 'subscription'
    );
  },
  wsLink,
  httpLink,
);

But I end up getting this error in the client:

WebSocket connection to 'wss://localhost/graphql/' failed: Error in connection establishment: net::ERR_CERT_AUTHORITY_INVALID

In looking at the docs (and exploring the APIs), I could not figure out how to configure WebSocketLink to accept a self-signed certificate. I am pretty sure that for development environments, all developers code with self signed certificates, so I know this should be doable. Any help in getting this working is much appreciated.

Interestingly, the HttpLink that I use for queries and mutations does not complain of the same self-signed certificates. If anyone from the apollo team sees this question, they should consider unifying the behavior of the two link types.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...