This repository has been archived by the owner on Nov 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support optional parsers in mutations and queries (#26)
- Loading branch information
Showing
16 changed files
with
361 additions
and
90 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@next-fetch/core-plugin": patch | ||
"@next-fetch/react-query": patch | ||
"@next-fetch/swr": patch | ||
--- | ||
|
||
Support optional input in `query` and `mutation` |
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
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,47 @@ | ||
import z from "zod"; | ||
import { mutation, query } from "@next-fetch/react-query"; | ||
import { userAgent } from "next/server"; | ||
|
||
export const config = { runtime: "experimental-edge" }; | ||
|
||
export const useRuntimeInfo = query( | ||
z.object({ name: z.string() }), | ||
async ({ name }) => { | ||
return `${name}, EdgeRuntime = ${EdgeRuntime}`; | ||
}, | ||
{ | ||
hookResponse(text) { | ||
return new Response(text, { | ||
headers: { "x-direct-request": "true" }, | ||
}); | ||
}, | ||
} | ||
); | ||
|
||
export const useRuntimeInfoMutation = mutation( | ||
z.object({ name: z.string() }), | ||
async function ({ name }) { | ||
return [ | ||
`runtime: ${EdgeRuntime}`, | ||
`input: ${name}`, | ||
`request browser: ${userAgent(this.request).browser?.name}`, | ||
]; | ||
}, | ||
{ | ||
hookResponse(data) { | ||
return new Response(`response is: ${JSON.stringify(data)}`); | ||
}, | ||
} | ||
); | ||
|
||
export const useNoArgs = query(async () => `${EdgeRuntime}`); | ||
export const useNoArgsMutation = query( | ||
async function () { | ||
return this.request.method; | ||
}, | ||
{ | ||
hookResponse(data) { | ||
return new Response(`response is: ${JSON.stringify(data)}`); | ||
}, | ||
} | ||
); |
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
Oops, something went wrong.
f732e3c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
next-fetch – ./packages/docs
next-fetch-vercel-labs.vercel.app
next-fetch-git-main-vercel-labs.vercel.app
next-fetch-pi.vercel.app
f732e3c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
next-swr-endpoints-example-app – ./packages/example-app
next-swr-endpoints-example-app.vercel.app
next-swr-endpoints-example-app-vercel-labs.vercel.app
next-swr-endpoints-example-app-git-main-vercel-labs.vercel.app