-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
feat(cli): add lb4 relation command #2426
Conversation
this is still WIP, waiting for comments on what we achieved so far. |
@strongloop/loopback-maintainers, PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oleg269 this is a very important contribution for the developer experience. I left some comments on typos an a proposal (not mandatory ) to list repositories, but so far LGTM 👍 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I manually tested this and it works as expected. Both hasMany
and belongsTo
update the models and create controllers.
The controllers don't transpile yet because the repository needs to be updated, but this is known.
Great work!
another minor comment; in the pull request comment markdown, a checkbox is marked completed with 'x', or space, instead of 'v' or no space. This will render the checklist correctly. |
@elv1s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I quickly skimmed through the pull request, don't see any obvious problems beyond missing test coverage for different relation types. Please add more tests to ensure all supported relation types are executed & covered.
packages/cli/test/integration/generators/relation.integration.js
Outdated
Show resolved
Hide resolved
packages/cli/test/integration/generators/model.relation.integration.js
Outdated
Show resolved
Hide resolved
I run I discovered two problems though: (1) +import { Product } from "./product.model";
@model()
export class Category extends Entity {
- @property({
- type: 'number',
- id: true,
- required: true,
- })
- id: number;
+ @property({
+ type: 'number',
+ id: true,
+ required: true,
+ })
+ id: number; Is there a way how to configure (2) return await this.categoryRepository.products(id).find(filter);
// Property 'products' does not exist on type 'CategoryRepository'.ts(2339) It would be great to add one test for each relation type where we will build the project after a relation was defined, to verify that we are scaffolding valid code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution @oleg269! I did a trial run and since this is WIP, I understand that what I'm pointing out might be implemented soon, so as a reminder, I do not see the repository files changed after running lb4 relation
for a Customer hasMany Order
scenario. I assume more tests are to follow as well.
EDIT: Just realized @bajtos mentioned what I'm talking about 👍
@bajtos |
Hi, new commit:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great progress!
Besides the comments below: What is the purpose of an empty file packages/cli/test/fixtures/relation/controllers/index.ts
? Can we remove it please?
packages/cli/generators/relation/templates/controller-relation-template-belongs-to.ts.ejs
Outdated
Show resolved
Hide resolved
packages/cli/generators/relation/templates/controller-relation-template-has-many.ts.ejs
Outdated
Show resolved
Hide resolved
packages/cli/generators/relation/templates/controller-relation-template-has-many.ts.ejs
Outdated
Show resolved
Hide resolved
packages/cli/generators/relation/templates/controller-relation-template-has-many.ts.ejs
Outdated
Show resolved
Hide resolved
Empty file packages/cli/test/fixtures/relation/controllers/index.ts was removed. |
Hi, I finished implementation lb4 relation command. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there!
@oleg269, seems like your PR is good to go. Could you please rebase and squash the commits? then we'll help you land. Thanks!! |
'lb4 openapi\n lb4 observer', | ||
======= | ||
'lb4 openapi\n lb4 relation', | ||
>>>>>>> c589f34... feat(cli): add lb4 relation command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI I squashed this fix in the commit because I forgot to remove these diff lines when rebasing.
The strings are found in : /loopback-next/packages/cli/node_modules/yeoman-generator/lib/index.js in the // Determine the app root
this.contextRoot = this.env.cwd;
let rootPath = findUp.sync('.yo-rc.json', {
cwd: this.env.cwd
});
rootPath = rootPath ? path.dirname(rootPath) : this.env.cwd;
if (rootPath !== this.env.cwd) {
this.log(
[
'',
'Just found a `.yo-rc.json` in a parent directory.',
'Setting the project root at: ' + rootPath
].join('\n')
);
this.destinationRoot(rootPath);
}
this.appname = this.determineAppname();
this.config = this._getStorage();
this._globalConfig = this._getGlobalStorage(); |
With mocha === ATTENTION - INVALID USAGE OF CONSOLE LOGS DETECTED ===
|
Still investigating... |
I tried running certain tests individually . "mocha_hasConsoleLogError8": "node packages/build/bin/run-mocha \"packages/cli/test/integration/generators/extension.integration.js\" ",
"mocha_hasConsoleLogError7": "node packages/build/bin/run-mocha \"packages/cli/test/integration/generators/observer.integration.js\" ",
"mocha_hasConsoleLogError6": "node packages/build/bin/run-mocha \"packages/cli/test/integration/generators/openapi-petstore.integration.js\" ",
"mocha_hasConsoleLogError5": "node packages/build/bin/run-mocha \"packages/cli/test/integration/generators/openapi-uspto-with-anonymous.integration.js\" ",
"mocha_hasConsoleLogError4": "node packages/build/bin/run-mocha \"packages/cli/test/integration/generators/openapi-uspto.integration.js\" ",
"mocha_hasConsoleLogError3": "node packages/build/bin/run-mocha \"packages/cli/test/integration/generators/repository.integration.js\" ",
"mocha_hasConsoleLogError1": "node packages/build/bin/run-mocha \"packages/cli/test/integration/generators/swagger-petstore.integration.js\" ",
"mocha_hasConsoleLogError2": "node packages/build/bin/run-mocha \"packages/cli/test/integration/generators/service.integration.js\" ",
"mocha_passes7": "node packages/build/bin/run-mocha \"packages/cli/test/integration/generators/hasmany.relation.integration.js\" ",
"mocha_passes6": "node packages/build/bin/run-mocha \"packages/cli/test/integration/generators/hasmany.relation.integration.js\" ",
"mocha_passes5": "node packages/build/bin/run-mocha \"packages/cli/test/integration/generators/belongsto.relation.integration.js\" ",
"mocha_passes4": "node packages/build/bin/run-mocha \"packages/cli/test/integration/generators/model.integration.js\" ",
"mocha_some_failures_versions": "node packages/build/bin/run-mocha \"packages/cli/test/integration/generators/example.integration.js\" ",
"mocha_passes3": "node packages/build/bin/run-mocha \"packages/cli/test/integration/generators/datasource.integration.js\" ",
"mocha_passes2": "node packages/build/bin/run-mocha \"packages/cli/test/integration/generators/controller.integration.js\" ",
"mocha_passes1": "node packages/build/bin/run-mocha \"packages/cli/test/integration/generators/app.integration.js\" ", Any entry of the form You'll notice that "mocha_passes6": "node packages/build/bin/run-mocha \"packages/cli/test/integration/generators/hasmany.relation.integration.js\" ",
"mocha_passes5": "node packages/build/bin/run-mocha \"packages/cli/test/integration/generators/belongsto.relation.integration.js\" ", run successfully. So is it a non-test file contributing to the problem (not a mocha test file)? Or is it a combination of the new test files called within the suite of the existing test files? @oleg269 , please look into this, thank you. :) |
@bajtos @emonddr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed best-generator tests: changed the current directory in which the file .yo-rc.json already exist.
Sounds reasonable.
coverage/coveralls — Coverage decreased (-0.4%) to 90.844%
This is a significant drop in our code coverage. I have reviewed the coverage report, there are quite few meaningful scenarios that are not covered by our tests.
Besides the places pointed out by my comments below, there are many error edge cases handled by relation/index.js
but not verified by any test. Please see the coverage report for that file here to find error scenarios needing a test.
Sorry for requesting further changes so late in the process. Unfortunately, no code coverage is reported when the test failed, that's why I was not aware of this problem earlier.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@oleg269 nice improvements 👍
Some of my earlier comments seem to be not addressed yet. The code coverage is dropping by 0.1% now, I think there are few more error scenarios to cover by our tests.
For example:
I also see quite few places where you are calling this.prompt()
and then catching any prompt errors to print a debug
log and call this.exit(err)
. Are these catch
block needed? Isn't it enough to let the error propagate through the promise chain up to Yeoman handler? See e.g. here:
https://github.com/strongloop/loopback-next/blob/d4300f70bd209f70aca4f3498bd12ffda2eda188/packages/cli/generators/relation/index.js#L352-L355
Last but not least: I see a lot of .then()
blocks in your new code. I believe we can use async functions and await
keyword in our CLI package, because we require Node.js 8+ and thus async/await support is always available. I guess it's late to rewrite the code you already have in your pull request, but could you please use async/await instead of .then()
and .catch()
in any future code you will write? Thanks 😄
packages/cli/test/integration/generators/negative-tests.relation.integration.js
Outdated
Show resolved
Hide resolved
packages/cli/test/integration/generators/negative-tests.relation.integration.js
Outdated
Show resolved
Hide resolved
packages/cli/test/integration/generators/negative-tests.relation.integration.js
Outdated
Show resolved
Hide resolved
packages/cli/test/integration/generators/negative-tests.relation.integration.js
Outdated
Show resolved
Hide resolved
packages/cli/test/integration/generators/negative-tests.relation.integration.js
Outdated
Show resolved
Hide resolved
@bajtos |
@oleg269 Thank you for the update. I have rebased your branch to latest master from |
@oleg269 I'm not sure if your last push was intentional as it makes the PR be in conflict with the upstream again. Please note I had pushed the rebased result back to your remote repo before your last one. |
@oleg269 I have squashed and rebased the PR into one commit. |
@oleg269 Thank you very much for putting great efforts to create and refine this PR. It's a good starting point to help improve model relations. I'm trying the CLI by myself and would like to see if there are simpler ways to prompt questions. I'm also trying |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kudos for @elv1s @TomerSalton to make it happen!
There is room for improvement in the developer experience. But it's a good starting point. I approve it and defer more refinement in future PRs.
Landed, thank you for the awesome contribution ❤️ |
Implementing add controller for relation; updating models using ast; implementing hasMany and
belongsTo relations. Still missing updating repository.
#1359
Checklist
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated