Skip to content

Commit

Permalink
feat: make all params optional #858
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim-Mazurok committed Jul 12, 2023
1 parent 4937e2e commit d92c33c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/query/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function vueWrapTypeWithMaybeRef(input: string): string {
.map((param) => {
const [paramName, paramType] = param.split(':');
if (paramType) {
return `${paramName}: MaybeRef<${paramType.trim()}>,`;
return `${paramName}: MaybeRef<${paramType.trim()} | undefined | null>,`;
} else {
return `${param},`;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type Awaited<O> = O extends AwaitedInput<infer T> ? T : never;
* @summary List all pets
*/
export const listPets = (
params?: MaybeRef<ListPetsParams>,
params?: MaybeRef<ListPetsParams | undefined | null>,
version = 1,
signal?: AbortSignal,
) => {
Expand All @@ -47,15 +47,15 @@ export const listPets = (
};

export const getListPetsQueryKey = (
params?: MaybeRef<ListPetsParams>,
params?: MaybeRef<ListPetsParams | undefined | null>,
version = 1,
) => ['v', version, 'pets', ...(params ? [params] : [])] as const;

export const getListPetsInfiniteQueryOptions = <
TData = Awaited<ReturnType<typeof listPets>>,
TError = Error,
>(
params?: MaybeRef<ListPetsParams>,
params?: MaybeRef<ListPetsParams | undefined | null>,
version = 1,
options?: {
query?: UseInfiniteQueryOptions<
Expand Down Expand Up @@ -93,7 +93,7 @@ export const useListPetsInfinite = <
TData = Awaited<ReturnType<typeof listPets>>,
TError = Error,
>(
params?: MaybeRef<ListPetsParams>,
params?: MaybeRef<ListPetsParams | undefined | null>,
version = 1,
options?: {
query?: UseInfiniteQueryOptions<
Expand Down Expand Up @@ -123,7 +123,7 @@ export const getListPetsQueryOptions = <
TData = Awaited<ReturnType<typeof listPets>>,
TError = Error,
>(
params?: MaybeRef<ListPetsParams>,
params?: MaybeRef<ListPetsParams | undefined | null>,
version = 1,
options?: {
query?: UseQueryOptions<
Expand Down Expand Up @@ -156,7 +156,7 @@ export const useListPets = <
TData = Awaited<ReturnType<typeof listPets>>,
TError = Error,
>(
params?: MaybeRef<ListPetsParams>,
params?: MaybeRef<ListPetsParams | undefined | null>,
version = 1,
options?: {
query?: UseQueryOptions<
Expand All @@ -181,7 +181,7 @@ export const useListPets = <
* @summary Create a pet
*/
export const createPets = (
createPetsBody: MaybeRef<CreatePetsBody>,
createPetsBody: MaybeRef<CreatePetsBody | undefined | null>,
version = 1,
) => {
return customInstance<Pet>({
Expand Down Expand Up @@ -248,7 +248,7 @@ export const useCreatePets = <TError = Error, TContext = unknown>(options?: {
* @summary Info for a specific pet
*/
export const showPetById = (
petId: MaybeRef<string>,
petId: MaybeRef<string | undefined | null>,
version = 1,
signal?: AbortSignal,
) => {
Expand All @@ -259,14 +259,16 @@ export const showPetById = (
});
};

export const getShowPetByIdQueryKey = (petId: MaybeRef<string>, version = 1) =>
['v', version, 'pets', petId] as const;
export const getShowPetByIdQueryKey = (
petId: MaybeRef<string | undefined | null>,
version = 1,
) => ['v', version, 'pets', petId] as const;

export const getShowPetByIdInfiniteQueryOptions = <
TData = Awaited<ReturnType<typeof showPetById>>,
TError = Error,
>(
petId: MaybeRef<string>,
petId: MaybeRef<string | undefined | null>,
version = 1,
options?: {
query?: UseInfiniteQueryOptions<
Expand Down Expand Up @@ -303,7 +305,7 @@ export const useShowPetByIdInfinite = <
TData = Awaited<ReturnType<typeof showPetById>>,
TError = Error,
>(
petId: MaybeRef<string>,
petId: MaybeRef<string | undefined | null>,
version = 1,
options?: {
query?: UseInfiniteQueryOptions<
Expand Down Expand Up @@ -333,7 +335,7 @@ export const getShowPetByIdQueryOptions = <
TData = Awaited<ReturnType<typeof showPetById>>,
TError = Error,
>(
petId: MaybeRef<string>,
petId: MaybeRef<string | undefined | null>,
version = 1,
options?: {
query?: UseQueryOptions<
Expand Down Expand Up @@ -366,7 +368,7 @@ export const useShowPetById = <
TData = Awaited<ReturnType<typeof showPetById>>,
TError = Error,
>(
petId: MaybeRef<string>,
petId: MaybeRef<string | undefined | null>,
version = 1,
options?: {
query?: UseQueryOptions<
Expand Down
2 changes: 1 addition & 1 deletion samples/vue-query/src/components/pet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { computed, unref } from 'vue';
import { useShowPetById } from '../api/endpoints/petstoreFromFileSpecWithTransformer';
const props = defineProps<{ petId: string }>();
const props = defineProps({ petId: String });
const petId = computed(() => props.petId);
const petQuery = useShowPetById(petId);
const pet = computed(() => unref(petQuery?.data));
Expand Down

0 comments on commit d92c33c

Please sign in to comment.