@openapi-typescript-infra/apollo-datasource-rest
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

apollo-datasource-rest

This module allows you to use typed OpenAPI-based method calls in an Apollo RESTDataSource subclass. The apollo-datasource-rest package is in fact deprecated, but we still use this heavily so I will start with this package and move to the new @apollo packages when we move the rest of the service.

To use this module, you should derive from TypedRESTDataSource<Paths, Context> instead of directly from RESTDataSource. The first generic argument should point to the paths object created by openapi-typescript, and the second to your Apollo server context.

Now, instead of calling this.get to use the generic REST client, call this.openapi.get to use the typed client (which in turn calls this.get after fixing up all the types and parameters).

See the test for an example using the PetStore API.

Package Sidebar

Install

npm i @openapi-typescript-infra/apollo-datasource-rest

Weekly Downloads

97

Version

3.0.0

License

MIT

Unpacked Size

88.8 kB

Total Files

30

Last publish

Collaborators

  • djmax