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

feat: add support for new version of @heyapi and use fetch client ins… #125

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

omridevk
Copy link

…tead of axios

@omridevk omridevk closed this Jun 12, 2024
@omridevk omridevk reopened this Jun 12, 2024
@omridevk omridevk marked this pull request as draft June 12, 2024 22:24
@omridevk
Copy link
Author

@7nohe @seriouslag
This is a draft PR that maybe can get some discussion going on how to make this less of a breaking change.
The new hey api clients doesn't provide a service anymore by default.

@omridevk
Copy link
Author

By the way, really great lib :D

@omridevk
Copy link
Author

omridevk commented Jun 12, 2024

I also noticed that in the main branch the react example the UI doesn't update when you create a new pet, this address this issue as well

@omridevk
Copy link
Author

might help address this as well:
#94

@seriouslag seriouslag added the enhancement New feature or request label Jun 12, 2024
Copy link
Collaborator

@seriouslag seriouslag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the amazing work!

// This is an example of using a hook that has all parameters optional;
// Here we do not have to pass in an object
const { data: _ } = useDefaultServiceFindPets();
const { data: _ } = useFindPets();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropping the use of tag names makes this a breaking change.

I must consider whether dropping the tag to generate the hook is helpful.
I see a benefit in having the tag help describe the hook, especially for large spec files.
I also see the beauty in not having the tag there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you referring the "defaultService"? because wasn't sure what to put there if there's no real concept of a service in the new client.

Copy link
Collaborator

@seriouslag seriouslag Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was referring to defaultService. For large spec files it’s a nice to have buckets to put similar api calls. dogService, catService, etc. makes DX better as you can discover api calls related to what you are working with using intelliSense/autocomplete

How are the names of the hooks being generated now? I believe they are generated from the method names of the generated client code from @hey-api. Does @hey-api use operationId or is it generated from the displayName, or something else? How are duplicate names handled.

I can imagine 2 generated hooks having the same or similar name using the clients code now that tags are not used in the names.

That was my stream of consciousness. I haven’t dug into the code yet.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seriouslag it is using the operationId and AFAIK it should be unique in the spec no?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe OperationId to be unique but not a required field in the OpenAPI spec.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I checked and it is either using the operationId, or build it using the URL, so we can definitely have a conflicts no?

@@ -42,8 +42,8 @@ function App() {
<div className="App">
<h1>Pet List</h1>
<ul>
{Array.isArray(data) &&
data?.map((pet, index) => (
{Array.isArray(data?.data) &&
Copy link
Collaborator

@seriouslag seriouslag Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data?.data is ugly right?
Why do we have another object with data inside of it?
This also introduces a breaking change.

Copy link
Author

@omridevk omridevk Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, was planning to dig into this and see what was changed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seriouslag fixed. not sure how I like the solution but you can you see it in this commit:
a341432

@omridevk
Copy link
Author

@seriouslag
Also added formatters and linters support, as those would never run on the queries folder but only on the requests folder

},
};

export const processOutput = async ({
Copy link
Collaborator

@seriouslag seriouslag Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work adding linting support.

I don't support putting linting and formatting in this PR.

@7nohe and I discussed dropping support in favor of letting users run the linters/formatters themselves.

If we were to keep the linters/formatters we should use this implementation to lint all the generated files instead of using the built-in implementation in @hey-api so that we don't have to worry if they break compatibility or change something

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np, i'll remove

@omridevk
Copy link
Author

Let's talk about the big elephant in the PR.
How do we make this a non breaking change?
I don't mind hopping on discord to discuss this.
Appreciate your feedback

@seriouslag
Copy link
Collaborator

Let's talk about the big elephant in the PR. How do we make this a non breaking change? I don't mind hopping on discord to discuss this. Appreciate your feedback

A breaking change is not no-go but this is a huge change as every single consumer has will have to change every hook. I feel we should not do that and offer a codemod or generate the old and new hooks and deprecate the old hooks. Or we could not break every hook and add back the service layer using the tag names. We could generate the services and this would be a non-breaking change.

@omridevk
Copy link
Author

omridevk commented Jun 15, 2024

Let's talk about the big elephant in the PR. How do we make this a non breaking change? I don't mind hopping on discord to discuss this. Appreciate your feedback

A breaking change is not no-go but this is a huge change as every single consumer has will have to change every hook. I feel we should not do that and offer a codemod or generate the old and new hooks and deprecate the old hooks. Or we could not break every hook and add back the service layer using the tag names. We could generate the services and this would be a non-breaking change.

yes there are several ways to go around this, I was thinking we can discuss it in discord or something so we can align on a way to tackle this with a plan, I don't mind the extra work.
An FYI, we might fork this and modify it to our needs as we don't need support for all other clients, only the new fetch, I have published a beta version with these changes to check if it is working in our env and everything seems to be working.

Regardless, i'd much rather contribute to this great lib and not only using a fork, you guys did really nice work here and i'd really want to give back :D

@seriouslag
Copy link
Collaborator

Let's talk about the big elephant in the PR. How do we make this a non breaking change? I don't mind hopping on discord to discuss this. Appreciate your feedback

A breaking change is not no-go but this is a huge change as every single consumer has will have to change every hook. I feel we should not do that and offer a codemod or generate the old and new hooks and deprecate the old hooks. Or we could not break every hook and add back the service layer using the tag names. We could generate the services and this would be a non-breaking change.

yes there are several ways to go around this, I was thinking we can discuss it in discord or something so we can align on a way to tackle this with a plan, I don't mind the extra work. An FYI, we might fork this and modify it to our needs as we don't need support for all other clients, only the new fetch, I have published a beta version with these changes to check if it is working in our env and everything seems to be working.

Regardless, i'd much rather contribute to this great lib and not only using a fork, you guys did really nice work here and i'd really want to give back :D

Thank you for all the work you have put into this! I have been away on vacation and will be for another week. Let’s touch base on discord when I get back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants