-
-
Notifications
You must be signed in to change notification settings - Fork 461
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
feat: add @urql/tanstack-react-router #3729
Open
schiller-manuel
wants to merge
2
commits into
urql-graphql:main
Choose a base branch
from
schiller-manuel:tanstack-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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': minor | ||
--- | ||
|
||
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,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,8 @@ | ||
{ | ||
"name": "@urql/tanstack-react-router", | ||
"version": "0.0.0", | ||
"exports": { | ||
".": "./src/index.ts" | ||
}, | ||
"exclude": ["node_modules"] | ||
} |
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": "0.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": "urql GraphQL Contributors", | ||
"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.43.2", | ||
"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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You are missing the export mappings, examples in other packages
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.
i was looking at
packages/react-urql/package.json
which also does not have export mappings.Why do we need export mappings here?
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.
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