Skip to content

Commit

Permalink
Fix for generating infinite/prefetch/ensure queries (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
7nohe authored Oct 10, 2024
1 parent 82b932b commit 866cb97
Show file tree
Hide file tree
Showing 24 changed files with 492 additions and 578 deletions.
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

0 comments on commit 866cb97

Please sign in to comment.