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

add MethodResponse for openapi-react-query #1945

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

freshgiammi
Copy link

Changes

Following suit from #1831, this PR adds the ability to get the return type of an endpoint from a OpenapiQueryClient client.

How to Review

The rationale implements the same behaviours as the referenced PR, only changing expected type for the incoming client to be compliant with the OpenapiQueryClient interface (which doesn't extend Client).

Checklist

  • Unit tests updated
  • docs/ updated (if necessary)
  • pnpm run update:examples run (only applicable for openapi-typescript)

@freshgiammi freshgiammi requested a review from a team as a code owner October 10, 2024 15:09
Copy link

changeset-bot bot commented Oct 10, 2024

⚠️ No Changeset found

Latest commit: 624a335

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@kerwanp
Copy link
Contributor

kerwanp commented Oct 14, 2024

Hi @freshgiammi, thanks for willing to contribute!

Is there any reason why this needs to be in openapi-react-query as it requires an openapi-fetch client anyway?

@kerwanp kerwanp added the openapi-react-query Relevant to openapi-react-query label Oct 14, 2024
@freshgiammi
Copy link
Author

freshgiammi commented Oct 14, 2024

Hi @kerwanp, the issue is that OpenapiQueryClient doesn't extend FetchClient, which means two things:

  • it can't be provided to the original MethodResponse included in openapi-fetch
  • it can't be passed to ClientPathsWithMethod in order to infer the Path type

I've pushed an improvement that solves the second point, by directly creating the PathsWithMethod type (which also makes auto-completion work correctly, my first implementation was naïve)

Path extends CreatedClient extends OpenapiQueryClient<infer Paths, infer _Media>
	? PathsWithMethod<Paths, Method>
	: never,

Doing this only means we only need FetchResponse from openapi-fetch to correctly resolve the return type. However I guess we could work around this too.

As for

Is there any reason why this needs to be in openapi-react-query as it requires an openapi-fetch client anyway?

Considering this can only be used for react-query clients, it doesn't make much sense to have it in the openapi-fetch package considering you'd have to bring in OpenapiQueryClient and the whole type chain (and users wouldn't use this, unless they use openapi-react-query too)

@kerwanp kerwanp self-assigned this Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
openapi-react-query Relevant to openapi-react-query
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants