-
Notifications
You must be signed in to change notification settings - Fork 474
feat: add @urql/tanstack-react-router #3729
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| # Changelog | ||
|
schiller-manuel marked this conversation as resolved.
Outdated
|
||
| 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "name": "@urql/tanstack-react-router", | ||
| "version": "1.0.0", | ||
|
schiller-manuel marked this conversation as resolved.
Outdated
|
||
| "exports": { | ||
| ".": "./src/index.ts" | ||
| }, | ||
| "exclude": [ | ||
| "node_modules", | ||
| "cypress", | ||
|
schiller-manuel marked this conversation as resolved.
Outdated
|
||
| "**/*.test.*", | ||
| "**/*.spec.*", | ||
| "**/*.test.*.snap", | ||
| "**/*.spec.*.snap" | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| { | ||
| "name": "@urql/tanstack-react-router", | ||
| "version": "1.0.0", | ||
|
schiller-manuel marked this conversation as resolved.
Outdated
|
||
| "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", | ||
|
schiller-manuel marked this conversation as resolved.
Outdated
|
||
| "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", | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are missing the export mappings, examples in other packages
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i was looking at
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. React-urql is a special case due to some old frameworks, vite is a good bundler so we should incorporate export mappings to future proof the package. What we do with react-urql is still a bit of a pickle, especially with regards to react-native |
||
| "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", | ||
|
schiller-manuel marked this conversation as resolved.
Outdated
|
||
| "react": ">=18.0.0", | ||
| "urql": "^4.0.0" | ||
| }, | ||
| "publishConfig": { | ||
| "access": "public", | ||
| "provenance": true | ||
| } | ||
| } | ||
| 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) | ||
| ); | ||
| } |
| 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'; |
Uh oh!
There was an error while loading. Please reload this page.