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

Fix for generating infinite/prefetch/ensure queries #158

Merged
merged 24 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8fd8a16
feat: add support for new version of @heyapi and use fetch client ins…
omridevk Jun 12, 2024
4d4e8d7
chore: remove comment
omridevk Jun 12, 2024
961428d
chore: remove comment
omridevk Jun 13, 2024
d34e761
fix: make sure to remove not relevant props from params
omridevk Jun 13, 2024
a341432
fix: get data from the client
omridevk Jun 13, 2024
0a1ff9d
fix: get data from the client
omridevk Jun 13, 2024
f716732
chore: release v1.4.2-beta.1
omridevk Jun 13, 2024
9eedb82
fix: add formatters and linters on the queries output as well
omridevk Jun 13, 2024
55ab44d
chore: release v1.4.2-beta.2
omridevk Jun 13, 2024
f8df50f
chore: release v1.4.2-beta.3
omridevk Jun 13, 2024
873c5f2
chore: release v1.4.2-beta.4
omridevk Jun 13, 2024
cb263a0
chore: release v1.4.2-beta.5
omridevk Jun 14, 2024
012f10f
chore: release v2.0.0
omridevk Jun 18, 2024
13d4587
adding client support
seriouslag Jul 21, 2024
ac05d7a
Merge branch 'main' into feat/new-openapi-client-support-2
7nohe Oct 7, 2024
e6d8ba8
chore: fix a react example
7nohe Oct 7, 2024
8377a0c
chore: fix a nextjs example
7nohe Oct 7, 2024
327454d
fix: support infinite queries
7nohe Oct 7, 2024
799b8c4
Merge branch 'v2' into fix/infinite-queries
7nohe Oct 7, 2024
43e463c
fix: Handle response in queryFn for prefetchQuery/ensureQueryData hooks
7nohe Oct 7, 2024
11a395b
fix: support prefetch/ensure functions
7nohe Oct 8, 2024
43ca318
chore: add tests
7nohe Oct 8, 2024
5d64da8
refactor: Use `toMatch` method to test buildRequestsOutputPath/buildQ…
7nohe Oct 8, 2024
9ceedca
fix: support mutations
7nohe Oct 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions examples/nextjs-app/app/components/PaginatedPets.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
"use client";

import { useDefaultServiceFindPaginatedPetsInfinite } from "@/openapi/queries/infiniteQueries";
import { useFindPaginatedPetsInfinite } from "@/openapi/queries/infiniteQueries";
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
import React from "react";

export default function PaginatedPets() {
const { data, fetchNextPage } = useDefaultServiceFindPaginatedPetsInfinite({
limit: 10,
tags: [],
const { data, fetchNextPage } = useFindPaginatedPetsInfinite({
query: {
limit: 10,
tags: [],
},
});

return (
<>
<h1>Pet List with Pagination</h1>
<ul>
{data?.pages.map((group, i) => (
<React.Fragment key={group.pets?.at(0)?.id}>
{group.pets?.map((pet) => (
<React.Fragment key={group?.pets?.at(0)?.id}>
{group?.pets?.map((pet) => (
<li key={pet.id}>{pet.name}</li>
))}
</React.Fragment>
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"generate:api": "rimraf ./openapi && node ../../dist/cli.mjs -i ../petstore.yaml --request ./request.ts --format=biome --lint=biome --base http://localhost:4010"
"generate:api": "rimraf ./openapi && node ../../dist/cli.mjs -i ../petstore.yaml --format=biome --lint=biome"
},
"dependencies": {
"@tanstack/react-query": "^5.32.1",
Expand Down
94 changes: 0 additions & 94 deletions examples/nextjs-app/request.ts

This file was deleted.

3 changes: 1 addition & 2 deletions examples/tanstack-router-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build": "vite build",
"serve": "vite preview",
"start": "vite",
"generate:api": "rimraf ./openapi && node ../../dist/cli.mjs -i ../petstore.yaml -c axios --request ./request.ts --format=biome --lint=biome"
"generate:api": "rimraf ./openapi && node ../../dist/cli.mjs -i ../petstore.yaml --format=biome --lint=biome"
},
"devDependencies": {
"@stoplight/prism-cli": "^5.5.2",
Expand All @@ -29,7 +29,6 @@
"@tanstack/react-router-with-query": "^1.58.7",
"@tanstack/router-devtools": "^1.58.7",
"@tanstack/start": "^1.58.7",
"axios": "^1.6.7",
"react": "^18.3.1",
"react-dom": "^18.3.1"
}
Expand Down
94 changes: 0 additions & 94 deletions examples/tanstack-router-app/request.ts

This file was deleted.

5 changes: 5 additions & 0 deletions examples/tanstack-router-app/src/fetchClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { client } from "../openapi/requests/services.gen";

client.setConfig({
baseUrl: "http://localhost:4010",
});
2 changes: 1 addition & 1 deletion examples/tanstack-router-app/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { RouterProvider, createRouter } from "@tanstack/react-router";
import React from "react";
import "./fetchClient";
import ReactDOM from "react-dom/client";
import { routeTree } from "./routeTree.gen";

Expand Down
1 change: 0 additions & 1 deletion examples/tanstack-router-app/src/routes/about.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createFileRoute } from "@tanstack/react-router";
import * as React from "react";

export const Route = createFileRoute("/about")({
component: AboutComponent,
Expand Down
10 changes: 5 additions & 5 deletions examples/tanstack-router-app/src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { createFileRoute } from "@tanstack/react-router";
import { ensureUseDefaultServiceFindPetsData } from "../../openapi/queries/ensureQueryData";
import { useDefaultServiceFindPetsSuspense } from "../../openapi/queries/suspense";
import { ensureUseFindPetsData } from "../../openapi/queries/ensureQueryData";
import { useFindPetsSuspense } from "../../openapi/queries/suspense";

export const Route = createFileRoute("/")({
loader: async ({ context }) => {
await ensureUseDefaultServiceFindPetsData(context.queryClient);
await ensureUseFindPetsData(context.queryClient);
},
component: HomeComponent,
});
function HomeComponent() {
const petsSuspense = useDefaultServiceFindPetsSuspense();
const petsSuspense = useFindPetsSuspense();
return (
<div className="p-2 flex gap-2">
<ul className="list-disc pl-4">
{petsSuspense.data.map((post) => {
{petsSuspense.data?.map?.((post) => {
return (
<li key={post.id} className="whitespace-nowrap">
<div>{post.name}</div>
Expand Down
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions src/cli.mts
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,7 @@ async function setupProgram() {
"Name of the response parameter used for next page",
"nextPage",
)
.option(
"--initialPageParam <value>",
"Initial page value to query",
"initialPageParam",
)
.option("--initialPageParam <value>", "Initial page value to query", "1")
.parse();

const options = program.opts<LimitedUserConfig>();
Expand Down
2 changes: 1 addition & 1 deletion src/constants.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const queriesOutputPath = "queries";
export const requestsOutputPath = "requests";

export const serviceFileName = "services.gen";
export const modalsFileName = "types.gen";
export const modelsFileName = "types.gen";

export const OpenApiRqFiles = {
queries: "queries",
Expand Down
Loading