Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
1 task
embpdaniel opened this issue Jul 1, 2019 · 4 comments
Open
1 task
Labels
developer-experience Issues affecting ease of use and overall experience of LB users feature good first issue Hacktoberfest Tasks ready for new contributors to work on help wanted

Comments

@embpdaniel
Copy link

embpdaniel commented Jul 1, 2019

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 #3288 (comment)

  • 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.

Hints:


🎆 Hacktoberfest 2020

Greetings 👋 to all Hacktoberfest 2020 participants!

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

  • Before you start working on this issue, please leave a comment to let others know.
  • If you are new to GitHub pull requests, then you can learn about the process in Submitting a pull request to LoopBack 4.
  • If this is your first contribution to LoopBack, then please take a look at our Developer guide.
  • Feel free to ask for help in #loopback-contributors channel, you can join our Slack workspace here.
@raymondfeng
Copy link
Contributor

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 bajtos changed the title Add support for unknown data sources lb4 service: support connectors not included in LoopBack's official list Jul 2, 2019
@bajtos bajtos added the developer-experience Issues affecting ease of use and overall experience of LB users label Jul 2, 2019
@bajtos
Copy link
Member

bajtos commented Jul 2, 2019

@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:

  • To find all LB connectors, query npmjs registry using an agreed-upon pattern. For example, we can use keyword like loopback-connector or two keywords loopback and `connector. Example query: https://api.npms.io/v2/search?q=keywords:loopback+connector&size=250 finds 180 connector-like packages, strangely enough our own mysql connector is not included.
  • Connector metadata like the connector type/base model, description of configuration options, etc. should be stored in per-connector package.json file and can be fetched e.g. via npmjs registry get package API. I think a better option is to use pacote, which is npm client library that leverages npm's cache to save network requests.

@AsjadMahmood
Copy link

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

@bajtos
Copy link
Member

bajtos commented Apr 3, 2020

@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.

@bajtos bajtos added the Hacktoberfest Tasks ready for new contributors to work on label Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
developer-experience Issues affecting ease of use and overall experience of LB users feature good first issue Hacktoberfest Tasks ready for new contributors to work on help wanted
Projects
None yet
Development

No branches or pull requests

4 participants