loopbackio / loopbackio/loopback-next
lb4 service: support connectors not included in LoopBack's official list
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1.1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 27
Description
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
- Create a sendgrid email datasource based on one of the existing sendgrid loopback connectors
- Run the
lb4 servicecommand, to tie this datasource to a service - 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
- Modify the logic in
lb4 serviceandlb4 repositoryand 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:
lb4 repositoryis already treating unknown connectors as compatible: https://github.com/strongloop/loopback-next/blob/b0a84b5adc30cac3614ea90e414b59cf76009ecf/packages/cli/generators/repository/index.js#L265-L276lb4 serviceinterprets "unknown" as "incompatible": https://github.com/strongloop/loopback-next/blob/b0a84b5adc30cac3614ea90e414b59cf76009ecf/packages/cli/generators/service/index.js#L191-L196- Changing
lb4 servicetoreturn result !== falseshould fix the issue. - The missing piece is how to write a test to verify the fix. The test should go to file
remote-service.integration.js, take a look at the test forlb4 repositoryfor inspiration here
🎆 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-contributorschannel, you can join our Slack workspace here.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read packages/cli/generators/service/index.js and the corresponding unknown-connector handling in packages/cli/generators/repository/index.js. Then inspect packages/cli/test/integration/generators/remote-service.integration.js and the repository integration test for its test structure. Done means the service generator accepts an unknown connector and the integration test verifies that behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- cli, testing-qa, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100