-
Notifications
You must be signed in to change notification settings - Fork 463
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add @urql/tanstack-react-router
- Loading branch information
1 parent
25d114d
commit cae0d95
Showing
13 changed files
with
548 additions
and
287 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,5 @@ | ||
--- | ||
'@urql/tanstack-react-router': major | ||
--- | ||
|
||
initial implementation of TanStack Router / Start Integration |
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 @@ | ||
# Changelog |
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,5 @@ | ||
## `tanstack-react-router-urql` | ||
|
||
A set of convenience utilities for using `urql` with SSR and `@tanstack/react-router` / `@tanstack/start`. | ||
|
||
More documentation is available at https://urql.dev/goto/docs/advanced/server-side-rendering/#tanstack--router-tanstack-start |
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,15 @@ | ||
{ | ||
"name": "@urql/tanstack-react-router", | ||
"version": "1.0.0", | ||
"exports": { | ||
".": "./src/index.ts" | ||
}, | ||
"exclude": [ | ||
"node_modules", | ||
"cypress", | ||
"**/*.test.*", | ||
"**/*.spec.*", | ||
"**/*.test.*.snap", | ||
"**/*.spec.*.snap" | ||
] | ||
} |
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,52 @@ | ||
{ | ||
"name": "@urql/tanstack-react-router", | ||
"version": "1.0.0", | ||
"description": "Convenience wrappers for using urql with SSR in @tanstack/react-router and @tanstack/start", | ||
"sideEffects": false, | ||
"homepage": "https://formidable.com/open-source/urql/docs/", | ||
"bugs": "https://github.com/urql-graphql/urql/issues", | ||
"license": "MIT", | ||
"author": "Manuel Schiller", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/urql-graphql/urql.git", | ||
"directory": "packages/tanstack-react-router-urql" | ||
}, | ||
"main": "dist/urql-tanstack-react-router.js", | ||
"module": "dist/urql-tanstack-react-router.es.js", | ||
"types": "dist/urql-tanstack-react-router.d.ts", | ||
"source": "src/index.ts", | ||
"files": [ | ||
"LICENSE", | ||
"CHANGELOG.md", | ||
"README.md", | ||
"dist/" | ||
], | ||
"scripts": { | ||
"clean": "rimraf dist", | ||
"check": "tsc --noEmit", | ||
"lint": "eslint --ext=js,jsx,ts,tsx .", | ||
"build": "rollup -c ../../scripts/rollup/config.mjs", | ||
"prepare": "node ../../scripts/prepare/index.js", | ||
"prepublishOnly": "run-s clean build" | ||
}, | ||
"devDependencies": { | ||
"@urql/core": "workspace:*", | ||
"urql": "workspace:*", | ||
"@types/react": "^18.3.8", | ||
"@types/react-dom": "^18.3.0", | ||
"graphql": "^16.0.0", | ||
"@tanstack/react-router": "^1.94.1", | ||
"react": "^18.0.0", | ||
"react-dom": "^18.0.0" | ||
}, | ||
"peerDependencies": { | ||
"@tanstack/react-router": ">=1.94.1", | ||
"react": ">=18.0.0", | ||
"urql": "^4.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public", | ||
"provenance": 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,54 @@ | ||
import * as React from 'react'; | ||
import type { SSRExchange, Client } from 'urql'; | ||
import { Provider } from 'urql'; | ||
|
||
export const SSRContext = React.createContext<SSRExchange | undefined>( | ||
undefined | ||
); | ||
|
||
/** Provider for `@urql/tanstack-react-router`. | ||
* | ||
* @remarks | ||
* `Provider` accepts a {@link Client} and provides it to all GraphQL hooks, it | ||
* also accepts an {@link SSRExchange} to distribute data when re-hydrating | ||
* on the client. | ||
* | ||
* @example | ||
* ```tsx | ||
* import { | ||
* UrqlProvider, | ||
* ssrExchange, | ||
* cacheExchange, | ||
* fetchExchange, | ||
* createClient, | ||
* } from '@urql/tanstack-react-router'; | ||
* | ||
* const ssr = ssrExchange(); | ||
* const client = createClient({ | ||
* url: 'https://trygql.formidable.dev/graphql/basic-pokedex', | ||
* exchanges: [cacheExchange, ssr, fetchExchange], | ||
* suspense: true, | ||
* }); | ||
* | ||
* const router = createRouter ({ | ||
* routeTree, | ||
* Wrap: ({ children }) => <UrqlProvider ssr={ssr} client={urqlClient}>{children}</UrqlProvider>, | ||
* }); | ||
* } | ||
* | ||
* ``` | ||
*/ | ||
export function UrqlProvider({ | ||
children, | ||
ssr, | ||
client, | ||
}: React.PropsWithChildren<{ | ||
ssr: SSRExchange; | ||
client: Client; | ||
}>) { | ||
return React.createElement( | ||
Provider, | ||
{ value: client }, | ||
React.createElement(SSRContext.Provider, { value: ssr }, children) | ||
); | ||
} |
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 * from 'urql'; | ||
export { useQuery } from './useQuery'; | ||
export { UrqlProvider, SSRContext } from './Provider'; |
Oops, something went wrong.