Skip to content

Commit

Permalink
fix: the goods
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim-Mazurok committed Nov 29, 2023
1 parent 6472eda commit 2077ded
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/src/pages/guides/custom-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const customInstance = async <T>({
data,
}: {
url: string;
method: 'get' | 'post' | 'put' | 'delete' | 'patch';
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
params?: any;
data?: BodyType<unknown>;
responseType?: string;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"test": "turbo run test",
"test:ci": "yarn test -- -- --run && yarn test:vue-query --run",
"test:vue-query": "cd ./samples/vue-query && yarn && yarn test",
"test:react-query:custom-client": "cd ./samples/react-query/custom-client && yarn && yarn test",
"lint": "turbo run lint",
"dev": "turbo run dev"
},
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ export const OutputClient = {
REACT_QUERY: 'react-query',
SVELTE_QUERY: 'svelte-query',
VUE_QUERY: 'vue-query',
SWR: 'swr',
} as const;

export type OutputClient = typeof OutputClient[keyof typeof OutputClient];
Expand Down
3 changes: 2 additions & 1 deletion samples/react-query/custom-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"start": "react-scripts start",
"build": "react-scripts build",
"eject": "react-scripts eject",
"generate-api": "node ../../../packages/orval/dist/bin/orval.js"
"generate-api": "node ../../../packages/orval/dist/bin/orval.js",
"test": "tsc --noEmit"
},
"eslintConfig": {
"extends": "react-app"
Expand Down
3 changes: 3 additions & 0 deletions samples/svelte-query/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ module.exports = {
es2017: true,
node: true,
},
rules: {
'@typescript-eslint/no-inferrable-types': 'off', // so that we can have `version: number | undefined | null = 1`, etc.
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { customInstance } from '../mutator/custom-instance';
*/
export const listPets = (
params?: ListPetsParams,
version = 1,
version: number = 1,
signal?: AbortSignal,
) => {
return customInstance<Pets>({
Expand All @@ -38,7 +38,10 @@ export const listPets = (
});
};

export const getListPetsQueryKey = (params?: ListPetsParams, version = 1) => {
export const getListPetsQueryKey = (
params?: ListPetsParams,
version: number = 1,
) => {
return [`/v${version}/pets`, ...(params ? [params] : [])] as const;
};

Expand All @@ -47,7 +50,7 @@ export const getListPetsQueryOptions = <
TError = Error,
>(
params?: ListPetsParams,
version = 1,
version: number = 1,
options?: {
query?: CreateQueryOptions<
Awaited<ReturnType<typeof listPets>>,
Expand Down Expand Up @@ -90,7 +93,7 @@ export const createListPets = <
TError = Error,
>(
params?: ListPetsParams,
version = 1,
version: number = 1,
options?: {
query?: CreateQueryOptions<
Awaited<ReturnType<typeof listPets>>,
Expand All @@ -114,7 +117,10 @@ export const createListPets = <
/**
* @summary Create a pet
*/
export const createPets = (createPetsBody: CreatePetsBody, version = 1) => {
export const createPets = (
createPetsBody: CreatePetsBody,
version: number = 1,
) => {
return customInstance<void>({
url: `/v${version}/pets`,
method: 'POST',
Expand Down Expand Up @@ -180,7 +186,7 @@ export const createCreatePets = <TError = Error, TContext = unknown>(options?: {
*/
export const showPetById = (
petId: string,
version = 1,
version: number = 1,
signal?: AbortSignal,
) => {
return customInstance<Pet>({
Expand All @@ -190,7 +196,7 @@ export const showPetById = (
});
};

export const getShowPetByIdQueryKey = (petId: string, version = 1) => {
export const getShowPetByIdQueryKey = (petId: string, version: number = 1) => {
return [`/v${version}/pets/${petId}`] as const;
};

Expand All @@ -199,7 +205,7 @@ export const getShowPetByIdQueryOptions = <
TError = Error,
>(
petId: string,
version = 1,
version: number = 1,
options?: {
query?: CreateQueryOptions<
Awaited<ReturnType<typeof showPetById>>,
Expand Down Expand Up @@ -242,7 +248,7 @@ export const createShowPetById = <
TError = Error,
>(
petId: string,
version = 1,
version: number = 1,
options?: {
query?: CreateQueryOptions<
Awaited<ReturnType<typeof showPetById>>,
Expand Down
2 changes: 1 addition & 1 deletion scripts/update-samples.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ await $`cd ./samples/react-query/form-url-encoded && yarn && yarn generate-api`;
await $`cd ./samples/react-query/form-url-encoded-mutator && yarn && yarn generate-api`;
await $`cd ./samples/react-query/hook-mutator && yarn && yarn generate-api`;
await $`cd ./samples/react-app-with-swr && yarn && yarn generate-api`;
// await $`cd ./samples/svelte-query && yarn && yarn generate-api`; // TODO: Fix error `Cannot find base config file "./.svelte-kit/tsconfig.json" [tsconfig.json]` and re-enable
await $`cd ./samples/svelte-query && yarn && yarn generate-api`;
await $`cd ./samples/vue-query && yarn && yarn generate-api`;

/** NOTE: use below to create a sample for `useNamedParameters: true` with code that is supposed to work and pass tests, but it will require changes in Orval code generation
Expand Down

0 comments on commit 2077ded

Please sign in to comment.