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
update artifacts of the todo-list example to the latest style generated by the LoopBack CLI #6598
Conversation
b69abbe
to
bb7a5e1
Compare
) {} | ||
|
||
@post('/todo-lists/{id}/image', { | ||
@post('/todo-list-images', { |
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.
The /todo-list/id/todo-list-image urls go into their own controller; see todo-list-todo-list-image.controller.ts.
bb7a5e1
to
7cae937
Compare
7cae937
to
5c7684c
Compare
@@ -182,6 +182,10 @@ $ npm start | |||
Server is running at http://127.0.0.1:3000 | |||
``` | |||
|
|||
{% include note.html content=" |
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 added this because there are some default filter objects that produce zero results or cause an http 500. So clearing these default filter objects provided by the API Explorer (swagger ui?) is best.
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.
GET /todos has a default filter of
{
"offset": 0,
"limit": 100,
"skip": 0,
"where": {
"additionalProp1": {}
},
"include": [
{
"relation": "string",
"scope": {
"offset": 0,
"limit": 100,
"skip": 0,
"where": {
"additionalProp1": {}
},
"include": [
{
"additionalProp1": {}
}
]
}
}
]
}
if user presses [Execute] button,
an exception is thrown
{
"error": {
"statusCode": 500,
"message": "Internal Server Error"
}
}
if we clear this filter and try again, the proper number of todos is returned.
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.
GET /todos/id
has filter
{
"offset": 0,
"limit": 100,
"skip": 0,
"include": [
{
"relation": "string",
"scope": {
"offset": 0,
"limit": 100,
"skip": 0,
"where": {
"additionalProp1": {}
},
"include": [
{
"additionalProp1": {}
}
]
}
}
]
}
produces 500 error as well. Must be cleared.
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.
GET /todos/count
has a where object
{
"additionalProp1": {}
}
that returns 0. Clearing it returns proper amount.
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.
GET /todo-lists/{id}/todo-list-image
and
/todo-lists/{id}/todo
have same filter which causes error 500. Clearing them works.
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.
perhaps I should change the note.html to
{% include note.html content=" When using the API Explorer, be sure to clear out any default filter object or where object as this may affect your results. " %}
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.
Do we have more details about what causes the 500 error? Any stacktrace?
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.
Do we have more details about what causes the 500 error? Any stacktrace?
GET /todos (with default filter above) returns:
Error: Invalid "filter.include" entries: {"relation":"string","scope":{"offset":0,"limit":100,"skip":0,"where":{"additionalProp1":{}},"include":[{"additionalProp1":{}}]}}
This is the full stack trace:
Server is running at http://[::1]:3000
Request GET /todos?filter=%7B%0A%20%20%22offset%22%3A%200%2C%0A%20%20%22limit%22%3A%20100%2C%0A%20%20%22skip%22%3A%200%2C%0A%20%20%22where%22%3A%20%7B%0A%20%20%20%20%22additionalProp1%22%3A%20%7B%7D%0A%20%20%7D%2C%0A%20%20%22include%22%3A%20%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%22relation%22%3A%20%22string%22%2C%0A%20%20%20%20%20%20%22scope%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22offset%22%3A%200%2C%0A%20%20%20%20%20%20%20%20%22limit%22%3A%20100%2C%0A%20%20%20%20%20%20%20%20%22skip%22%3A%200%2C%0A%20%20%20%20%20%20%20%20%22where%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%22additionalProp1%22%3A%20%7B%7D%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%22include%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22additionalProp1%22%3A%20%7B%7D%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%5D%0A%7D failed with status code 500. Error: Invalid "filter.include" entries: {"relation":"string","scope":{"offset":0,"limit":100,"skip":0,"where":{"additionalProp1":{}},"include":[{"additionalProp1":{}}]}}
at Object.includeRelatedModels (/Users/dremond/Documents/PRs_LoopBack/authTwo/loopback-next/packages/repository/dist/relations/relation.helpers.js:70:21)
at TodoRepository.includeRelatedModels (/Users/dremond/Documents/PRs_LoopBack/authTwo/loopback-next/packages/repository/dist/repositories/legacy-juggler-bridge.js:389:28)
at TodoRepository.find (/Users/dremond/Documents/PRs_LoopBack/authTwo/loopback-next/packages/repository/dist/repositories/legacy-juggler-bridge.js:286:21)
at processTicksAndRejections (internal/process/task_queues.js:94:5)
at async /Users/dremond/Documents/PRs_LoopBack/authTwo/loopback-next/packages/rest/dist/providers/invoke-method.provider.js:40:32
at async /Users/dremond/Documents/PRs_LoopBack/authTwo/loopback-next/packages/express/dist/middleware-interceptor.js:82:25
at async /Users/dremond/Documents/PRs_LoopBack/authTwo/loopback-next/packages/express/dist/middleware-interceptor.js:82:25
at async /Users/dremond/Documents/PRs_LoopBack/authTwo/loopback-next/packages/rest/dist/providers/send.provider.js:39:32
at async MiddlewareSequence.handle (/Users/dremond/Documents/PRs_LoopBack/authTwo/loopback-next/packages/rest/dist/sequence.js:201:9)
at async HttpHandler._handleRequest (/Users/dremond/Documents/PRs_LoopBack/authTwo/loopback-next/packages/rest/dist/http-handler.js:69:9)
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 opened a separate issue #6641 to track this potential problem in the API Explorer. It isn't related to the re-generated artifacts of this todolist example per se.
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.
Same error happens with existing todo-list example
Server is running at http://127.0.0.1:3000
Unhandled error in GET /todos?filter=%7B%0A%20%20%22offset%22%3A%200%2C%0A%20%20%22limit%22%3A%20100%2C%0A%20%20%22skip%22%3A%200%2C%0A%20%20%22where%22%3A%20%7B%0A%20%20%20%20%22additionalProp1%22%3A%20%7B%7D%0A%20%20%7D%2C%0A%20%20%22fields%22%3A%20%7B%0A%20%20%20%20%22id%22%3A%20true%2C%0A%20%20%20%20%22title%22%3A%20true%2C%0A%20%20%20%20%22desc%22%3A%20true%2C%0A%20%20%20%20%22isComplete%22%3A%20true%2C%0A%20%20%20%20%22todoListId%22%3A%20true%0A%20%20%7D%2C%0A%20%20%22include%22%3A%20%5B%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%22relation%22%3A%20%22string%22%2C%0A%20%20%20%20%20%20%22scope%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22offset%22%3A%200%2C%0A%20%20%20%20%20%20%20%20%22limit%22%3A%20100%2C%0A%20%20%20%20%20%20%20%20%22skip%22%3A%200%2C%0A%20%20%20%20%20%20%20%20%22where%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%22additionalProp1%22%3A%20%7B%7D%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%22fields%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%22additionalProp1%22%3A%20%7B%7D%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20%22include%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22additionalProp1%22%3A%20%7B%7D%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%5D%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%5D%0A%7D: 500 Error: Invalid "filter.include" entries: {"relation":"string","scope":{"offset":0,"limit":100,"skip":0,"where":{"additionalProp1":{}},"fields":{"additionalProp1":{}},"include":[{"additionalProp1":{}}]}}
at Object.includeRelatedModels (/Users/dremond/Documents/PRs_LoopBack/authTwo/loopback4-example-todo-list/node_modules/@loopback/repository/dist/relations/relation.helpers.js:70:21)
at TodoRepository.includeRelatedModels (/Users/dremond/Documents/PRs_LoopBack/authTwo/loopback4-example-todo-list/node_modules/@loopback/repository/dist/repositories/legacy-juggler-bridge.js:389:28)
at TodoRepository.find (/Users/dremond/Documents/PRs_LoopBack/authTwo/loopback4-example-todo-list/node_modules/@loopback/repository/dist/repositories/legacy-juggler-bridge.js:286:21)
at processTicksAndRejections (internal/process/task_queues.js:94:5)
at async /Users/dremond/Documents/PRs_LoopBack/authTwo/loopback4-example-todo-list/node_modules/@loopback/rest/dist/providers/invoke-method.provider.js:40:32
at async /Users/dremond/Documents/PRs_LoopBack/authTwo/loopback4-example-todo-list/node_modules/@loopback/express/dist/middleware-interceptor.js:82:25
at async /Users/dremond/Documents/PRs_LoopBack/authTwo/loopback4-example-todo-list/node_modules/@loopback/express/dist/middleware-interceptor.js:82:25
at async /Users/dremond/Documents/PRs_LoopBack/authTwo/loopback4-example-todo-list/node_modules/@loopback/rest/dist/providers/send.provider.js:39:32
at async MiddlewareSequence.handle (/Users/dremond/Documents/PRs_LoopBack/authTwo/loopback4-example-todo-list/node_modules/@loopback/rest/dist/sequence.js:201:9)
at async HttpHandler._handleRequest (/Users/dremond/Documents/PRs_LoopBack/authTwo/loopback4-example-todo-list/node_modules/@loopback/rest/dist/http-handler.js:69:9)
@raymondfeng ^^
@@ -69,6 +69,28 @@ lb4 repository | |||
Repository TodoListImageRepository was created in src/repositories/ | |||
``` | |||
|
|||
### Create the controller |
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.
This step was missing in the documentation. The controller appeared in the finished sample, but the docs didn't contain the steps. Adding the step in.
@@ -103,6 +125,45 @@ $ lb4 relation | |||
Relation BelongsTo was created in src/ | |||
``` | |||
|
|||
As you can see, this created the relational controllers |
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.
Following the same idea that is used in the todo/id/todlist controller. Move the only method to the todo controller, and delete the relation controller that only has one method. We'll do the same thing here for the /todo-list-image/id/todo-list method.
bfb2ead
to
c302288
Compare
c302288
to
bc693c3
Compare
Looks like I need to add more test cases... |
25cb2e3
to
9507f33
Compare
All tests are passing. Just need an approval :) |
docs/site/tutorials/todo-list/todo-list-tutorial-has-one-relation.md
Outdated
Show resolved
Hide resolved
9507f33
to
bbc58e6
Compare
Update the artifacts of this example to the latest style generated by the LoopBack CLI. Update the documentation to add the step of adding TodoListImage controller. Signed-off-by: Dominique Emond <dremond@ca.ibm.com>
bbc58e6
to
d46849e
Compare
Update the artifacts of this example
to the latest style generated by the
LoopBack CLI.
Update the documentation to add the
step of adding TodoListImage controller.
Checklist
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated