Search code examples
node.jsapollo-serverapollo-datasource-rest

How to use client certificate in @apollo/datasource-rest


I am using subclass of @apollo/datasource-rest for fetching data from REST API's in my project. I need to add a client certificate in every request in made in my subclass. I know that It is possible to add certificate in the https https.Agent and it can used in the previous version of apollo datasource rest apollo-datasource-rest like this

this.get(<reqparams> , {agent : <https agent with certificate>})

Not sure how to use the same with new version of apollo datasouce (@apollo/datasource-rest)


Solution

  • If you want to use a custom agent, you need to pass a custom fetch to RESTDataSource. The lack of support for agent is explicitly called out in the FetcherRequestInit type:

      // We explicitly do not support non-portable options like `node-fetch`'s
      // `agent`.