loopbackio / loopback-next

LoopBack makes it easy to build modern API applications that require complex integrations.
https://loopback.io
Other
4.97k stars 1.07k forks source link

lb4 service: support connectors not included in LoopBack's official list #3288

Open embpdaniel opened 5 years ago

embpdaniel commented 5 years ago

Suggestion

A connector such as the sendgrid loopback connector, is a connector that does not require CRUD commands and it is not a REST data source. This currently seems to make it impossible to run the lb4 service command against such a connector, as the generator will expect a REST datasource.

My suggestion would be to add a new datasource metadata for a connector such as this (one that doesn't require CRUD and is not a REST api), so the service generator is able to recognize it as a valid datasource and make its methods available to controllers.

Use Cases

This will be useful for connecting a service to an email library such as sendgrid, or to utilize other libraries that provide a high-level API for their REST implementations. This includes just about any 3rd party library that is not controlled via REST directly.

Examples

  1. Create a sendgrid email datasource based on one of the existing sendgrid loopback connectors
  2. Run the lb4 service command, to tie this datasource to a service
  3. Inject the service into a controller, to give the user the ability to send emails based on some API request

Acceptance criteria

based on https://github.com/strongloop/loopback-next/issues/3288#issuecomment-507628571

Hints:


🎆 Hacktoberfest 2020

Greetings :wave: to all Hacktoberfest 2020 participants!

Here are few tips 👀 to make your start easier, see also #6456:

raymondfeng commented 5 years ago

At the moment, we use "baseModel": "Model", to tell a connector is for service apis. See https://github.com/strongloop/loopback-workspace/blob/master/available-connectors.json

bajtos commented 5 years ago

@raymondfeng the problem is that the sendgrid connector is not listed in available-connectors file.

IMO, it's not reasonable to expect all community-maintained connectors to be listed in that file.

For the short term, I am proposing to modify the logic in lb4 service and lb4 repository and when we don't have metadata about the base model used by the connector, then assume the connector is compatible with both services and repositories. Maybe print a hint that we don't know if the connector is compatible.

I think the first part can be easily accomplished by changing the following line to return true instead of null:

https://github.com/strongloop/loopback-next/blob/6bbc44f769bf5ed2aaa2012ef4b64c30d68ee928/packages/cli/lib/utils.js#L493-L494

For longer term, I think we should replace available-connectors file with a decentralized approach:

AsjadMahmood commented 4 years ago

Any Solution regarding this. Stuck in sending email using sendgrid in loopback 4

bajtos commented 4 years ago

@AsjadMahmood you can use the following workaround:

  1. Create the datasource via lb4 datasource using a supported service connector first, e.g. REST. Enter any valid configuration, you will change this later.
  2. Create the service via lb4 service.
  3. Edit the configuration of your datasource, change it to use sendgrid connector. Update your project dependencies - remove the connector installed by lb4 datasource and add your connector.