-
Notifications
You must be signed in to change notification settings - Fork 8
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
Implement getSbom using a generated api client. #121
Implement getSbom using a generated api client. #121
Conversation
@chirino, having the client code automatically generated could effectively replace the REST code which is quite repeatable is obviously a good idea. I have the following reservations at this stage :
Regarding the first point, I think we need to see the use of such approach as a replacement layer. |
The benefits of the extra lines of code are:
Wonder what additional React Query support they want to add as this PR shows that the two integrate fine. |
8983e54
to
7650a82
Compare
Updated PR to use new axios client. Seems to integrate better with the existing |
this PR depends on hey-api/openapi-ts#811 getting merged. |
5ac1911
to
5b7ac42
Compare
Update to new version of |
b1e65ca
to
83d26b6
Compare
Thanks @chirino for this PR, it helps a lot to see code and visualize code to have a better understanding. Some general thoughts about "Api client" and "React Query" as it seems it was mentioned: Client
React Query
In regards of the auto generated client. I think every solution should solve a problem. And we need to identify a problem. My personal view about introducing @hey-api/openapi-ts :
At this point, I am afraid of introducing a hard dependency that rather than help would block us.
In summary, although I appreciate the PR I think it should be carefully evaluated. I wouldn't like to accept a contribution and then leave the long term maintainers to deal with a decision not supported by them. I really do not want to sound not welcoming contributions, but we need to be aware that although this seems a simple things it has a significant impact on the daily work of whoever writes big pieces of code daily in this repository. |
I think you are missing the point... the Trustify server SHOULD have a stable and easy to use openapi definition. .. We are asking the UI team to help us make sure it becomes that and STAYS that way. Yes this might help the UI by not needing to write as much boiler plate code, but the real value is that you guys become our acceptance testers for the APIs. |
I think 2 problems it'd help solve would be:
|
I totally agree the UI cannot and shouldn't be a dependency to any back-end. Quite the contrary, to be able to fulfill its main purpose of offering the best and most efficient UXD, the Web development' stack requires flexibility and we must keep a vision of independent layers. Of course the UI will catch bugs when the API is broken but it's not its role. No matter what the UI is about UXD. Also we need to keep in mind the GraphQL API support which adds another "layer" where we need to stay flexible. |
It seems the problem we are trying to address is "how to ensure the API contract is correctly defined".
The kind of things I continuously raise against the API contract are things related to design not to implementation, like the ones below I created today: trustify/issues/624 - Filter products by org does not work We will always gladly contribute as Acceptance testers to the Contract as we also benefit from it. But steeping our feet on reality, I would say we must focus on API Design (which won't be solved, neither make noise, by pushing an auto-generated API on any client) |
* Initial step in implementing trustification#119 The generated code lived in to the `client/src/app/client`. The goal should be to replace all the api calls with client calls. Added `npm run generate` and `npm run prettier` sub commands. Signed-off-by: Hiram Chirino <hiram@hiramchirino.com>
83d26b6
to
e48cb55
Compare
Adding this increases the client/dist/js dir by 15k. |
Reformated PR with prettier |
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.
@chirino I discovered a thing that need to be addressed. See my comment in the code itself please.
client/src/app/queries/sboms.ts
Outdated
queryFn: async () => | ||
id === undefined ? undefined : (await getSbom({ path: { id } })).data, |
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.
@chirino I've been doing further tests. I found a problem I would really like to be addressed:
- The Axios errors are gone.
How to reproduce:
- Open the file
client/src/app/pages/sbom-details
and add this code to print the error in the code so you can it what I mean:
useEffect(() => {
if (fetchError) {
console.log(fetchError);
}
}, [fetchError]);
- Start the server using
npm run start:dev
- Open your browser in a non existent SBOM. E.g. open your browser at http://localhost:3000/sboms/anything
- Open your browser dev tools and you will see something like the image below:
So what is the problem?
- Due to this change, the auto retry of ReactQuery stopped working
- The Actual error returned from the server is gone.
This is how it looks with the original code and without the autogenerated code:
- Notice that the feature of auto retry of ReactQuery works, you see 3 GET errors in the console
- The original Axios error generated by the server is still there
Keeping the errors is crucial and I would be against losing them. Is there some fix you could apply please?
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.
Will look into this.
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 should be fixed now. The error was not getting thrown. Had to enable an option to get the desired behavior.
…deal with them as expected. Signed-off-by: Hiram Chirino <hiram@hiramchirino.com>
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.
Thanks for the latest fix @chirino . Let's see how we can incrementally use these endpoints/models and what we find on that journey.
The generated code lived in to the
client/src/app/client
. The goal should be to replace all the api calls with client calls.The
client/src/app/client-config
deals with the axios integration similar toaxios-config
, right now we can't handle 401 retries as our existing client does it. Need to think harder about how to implement similar functionality.