-
-
Notifications
You must be signed in to change notification settings - Fork 798
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix queries & mutations to work with trailing slash config (patch) (#…
…2392) * Added trailingslash support for API endpoints. * Accidentally RM'd actual condition it was meant to be based upon. * simplify integration test Co-authored-by: Brandon Bayer <[email protected]>
- Loading branch information
Showing
13 changed files
with
171 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default async function getBasic() { | ||
return "basic-result" | ||
} |
4 changes: 4 additions & 0 deletions
4
test/integration/trailing-slash/app/queries/getIncremented.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
let count = 0 | ||
export default async function getBasic() { | ||
return count++ | ||
} |
30 changes: 30 additions & 0 deletions
30
test/integration/trailing-slash/app/queries/getPaginated.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {paginate, resolver} from "blitz" | ||
|
||
const dataset = Array.from(Array(100).keys()) | ||
|
||
type Args = { | ||
skip: number | ||
take: number | ||
where?: {value: {gte: number}} | ||
} | ||
|
||
export default resolver.pipe(async ({skip = 0, take = 100, where}: Args) => { | ||
const {items, hasMore, nextPage, count} = await paginate({ | ||
skip, | ||
take, | ||
count: async () => dataset.length, | ||
query: async (paginateArgs) => | ||
dataset | ||
.filter((i) => { | ||
if (!where) return true | ||
return i >= where.value.gte | ||
}) | ||
.slice(paginateArgs.skip, paginateArgs.skip + paginateArgs.take), | ||
}) | ||
return { | ||
items, | ||
hasMore, | ||
nextPage, | ||
count, | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
presets: ["blitz/babel"], | ||
plugins: [], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
trailingSlash: true, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import {AppProps} from "blitz" | ||
import {ReactQueryDevtools} from "react-query/devtools" | ||
|
||
export default function App({Component, pageProps}: AppProps) { | ||
return ( | ||
<> | ||
<Component {...pageProps} /> | ||
<ReactQueryDevtools /> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {BlitzScript, Document, DocumentHead, Html, Main} from "blitz" | ||
|
||
class MyDocument extends Document { | ||
// Only uncomment if you need to customize this behaviour | ||
// static async getInitialProps(ctx: DocumentContext) { | ||
// const initialProps = await Document.getInitialProps(ctx) | ||
// return {...initialProps} | ||
// } | ||
|
||
render() { | ||
return ( | ||
<Html lang="en"> | ||
<DocumentHead /> | ||
<body> | ||
<Main /> | ||
<BlitzScript /> | ||
</body> | ||
</Html> | ||
) | ||
} | ||
} | ||
|
||
export default MyDocument |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import getBasic from "app/queries/getBasic" | ||
import {useQuery} from "blitz" | ||
import {Suspense} from "react" | ||
|
||
function Content() { | ||
const [result] = useQuery(getBasic, undefined) | ||
return <div id="content">{result}</div> | ||
} | ||
|
||
function Page() { | ||
return ( | ||
<div id="page"> | ||
<Suspense fallback={"Loading..."}> | ||
<Content /> | ||
</Suspense> | ||
</div> | ||
) | ||
} | ||
|
||
export default Page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* eslint-env jest */ | ||
import {findPort, killApp, launchApp, renderViaHTTP} from "lib/blitz-test-utils" | ||
import webdriver from "lib/next-webdriver" | ||
import {join} from "path" | ||
|
||
const context: any = {} | ||
jest.setTimeout(1000 * 60 * 5) | ||
|
||
describe("Queries", () => { | ||
beforeAll(async () => { | ||
context.appPort = await findPort() | ||
context.server = await launchApp(join(__dirname, "../"), context.appPort, { | ||
env: {__NEXT_TEST_WITH_DEVTOOL: 1}, | ||
}) | ||
|
||
const prerender = ["/use-query"] | ||
await Promise.all(prerender.map((route) => renderViaHTTP(context.appPort, route))) | ||
}) | ||
afterAll(() => killApp(context.server)) | ||
|
||
describe("useQuery", () => { | ||
it("should render query result", async () => { | ||
const browser = await webdriver(context.appPort, "/use-query") | ||
let text = await browser.elementByCss("#page").text() | ||
expect(text).toMatch(/Loading/) | ||
await browser.waitForElementByCss("#content") | ||
text = await browser.elementByCss("#content").text() | ||
expect(text).toMatch(/basic-result/) | ||
if (browser) await browser.close() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"baseUrl": "./", | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve", | ||
"incremental": true, | ||
"tsBuildInfoFile": ".tsbuildinfo", | ||
"paths": { | ||
"lib/*": ["../../lib/*"] | ||
} | ||
}, | ||
"exclude": ["node_modules"], | ||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"] | ||
} |