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

Optional arguments are sent as undefined #16

Closed
Richard87 opened this issue Jan 12, 2021 · 6 comments
Closed

Optional arguments are sent as undefined #16

Richard87 opened this issue Jan 12, 2021 · 6 comments

Comments

@Richard87
Copy link

Hi!

I have this definition:

export type ApiCoursesJobsGetSubresourceApiArg = {
    id: string;
    /** The collection page number */
    page?: number;
    /** The number of items per page */
    itemsPerPage?: number;
};

When I run const {data, ...response} = useApiCoursesJobsGetSubresourceQuery({id: 27, itemsPerPage: 100, page:1}) without page or itemsPerPage, they are included in the request as string values "undefined", with a 400 Bad request error message from the API...

Does this bug belong in rtk-query-codegen or in rtk-query, or something I should fix on my end? :)

@msutkowski
Copy link
Member

Looks like @kahirokunn opened a PR for this earlier. We'll just want to add test cases for that (sorry I missed them 😞) and then I'd recommend using the CSB build.

@msutkowski
Copy link
Member

msutkowski commented Jan 12, 2021

@Richard87 Can you confirm you're using fetchBaseQuery as the default generated baseQuery? It might be helpful if you dropped a gist of the generated client if you're able to.

@msutkowski
Copy link
Member

@Richard87 Would you mind trying this version of rtk-query in your project and reporting back?

yarn add https://pkg.csb.dev/rtk-incubator/rtk-query/commit/8d6e1c9b/@rtk-incubator/rtk-query

@Richard87
Copy link
Author

Hi! Yes, I'm using FetchBaseQuery

here is my generated file: https://gist.github.com/Richard87/c29f22ca2649afe237c73fcd9853195b (I replaced - and : with _ in all names).

I can confirm at the commit over (https://pkg.csb.dev/rtk-incubator/rtk-query/commit/8d6e1c9b/@rtk-incubator/rtk-query) does not have the bug :)

@kahirokunn
Copy link
Contributor

kahirokunn commented Jan 13, 2021

#16 (comment)
By the way, I tried this, and it removed all my undefined. 👋

@msutkowski
Copy link
Member

Alright, released 0.2, please upgrade :)

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

No branches or pull requests

3 participants