urql
A highly customizable and versatile GraphQL client for React
More documentation is available at formidable.com/open-source/urql.
A highly customizable and versatile GraphQL client for React
A highly customizable and versatile GraphQL client for React
More documentation is available at formidable.com/open-source/urql.
sourcesContent in published packages
Submitted by @kitten (See #3755)hasNext to the query and mutation results
Submitted by @JoviDeCroock (See #3703)@urql/core as a peer dependency as well as a regular dependency
Submitted by @kitten (See #3579)context.suspense and fallback to checking client.suspense
Submitted by @JoviDeCroock (See #3427)useQuery and useSubscription to fail when they’re called in their state after a render that changes pause. This would previously cause internal dependencies to be outdated and the source to be discarded immediately in some cases
Submitted by @kitten (See #3323)react imports to namespace imports, and update build process for CommonJS outputs to interoperate with __esModule marked modules again
Submitted by @kitten (See #3251)Client from Context. Previously, urql kept a legacy default client in its context, with default exchanges and calling an API at /graphql. This has now been removed and you will have to create your own Client if you were relying on this behaviour
Submitted by @JoviDeCroock (See #3033)hasNext: true is set, which indicates deferred or streamed results
Submitted by @kitten (See #3103)sourcesContent, including additional source files, and had incorrect paths in some of them
Submitted by @kitten (See #3053)wonka@^6.3.0
Submitted by @kitten (See #3104)urql bindings packages
Submitted by @kitten (See #3079)variables properties optional when a type from TypedDocumentNode has no Variables or all optional Variables. Previously this would break for wrappers, e.g. in code generators, or when the type didn't quite match what we'd expect
Submitted by @kitten (See #3022)fetching going to false after changing variables in a subscription, by @JoviDeCroock (See #2667)wonka@^6.0.0), which has no breaking changes but is built to target ES2015 and comes with other minor improvements.
The library has fully been migrated to TypeScript which will hopefully help with making contributions easier!, by @kitten (See #2504)setState) may recursively schedule a mount, which then disabled other setState updates from being processed. Previously we assumed that React used a trampoline scheduler for updates, however it appears that setState can recursively start more React work, by @kitten (See #2556)@urql/core in urql package and CommonJS output for all other CommonJS-first packages. This ensures that Node.js' cjs-module-lexer can correctly identify re-exports and report them properly. Otherwise, this will lead to a runtime error, by @kitten (See #2485)useQuery implementation, use-sync-external-store seems to be causing some unexpected timing issues, by @JoviDeCroock (See #2308)useQuery implementation to avoid an aborted render on initial mount. We abort a render-on-update once when the state needs to be updated according to the OperationResult source we need to listen to and execute. However, we can avoid this on the initial mount as we've done in a prior version. This fix does not change any of the current behaviour, but simply avoids the confusing state transition on mount, by @kitten (See #2227)use-sync-external-store, by @JoviDeCroock (See #2223)use-sync-external-store package and useSyncExternalStore hook in useQuery implementation to bring the state synchronisation in React in line with React v18. While the current implementation works already with React Suspense and React Concurrent this will reduce the maintenance burden of our implementation and ensure certain guarantees so that React doesn't break us, by @JoviDeCroock (See #2164)useMutation not working correctly with React 18, by @Dremora (See #2158)graphql to include ^16.0.0.
As always when upgrading across many packages of urql, especially including @urql/core we recommend you to deduplicate dependencies after upgrading, using npm dedupe or npx yarn-deduplicate, by @kitten (See #2133)executeQuery, this scenario occured when the query has variables, there would be cases where on the first call it would think that the dependencies had changed (previous request vs current request) which made the source reset to null, by @JoviDeCroock (See #1982)useQuery's executeQuery state updates, where some calls wouldn't trigger a source change and start a request when the hook was paused, by @kitten (See #1722)useSubscription would endlessly loop when the callback wasn't memoized, by @JoviDeCroock (See #1384)useQuery calls would result in cross-component updates, by @JoviDeCroock (See #1383)pollInterval option from useQuery. Instead please consider using useEffect calling executeQuery on an interval, by @kitten (See #1374)useQuery to apply a consistent Suspense cache (torn down queries will still eliminate stale values) and support all Concurrent Mode edge cases. This work is based on useMutableSource's mechanisms and allows React to properly fork lanes since no implicit state exists outside of useState in the implementation. The useSubscription hook has been updated similarly without a cache or retrieving values on mount, by @kitten (See #1335)operationName property from Operations. The new Operation.kind property is now preferred. If you're creating new operations you may also use the makeOperation utility instead.
When upgrading @urql/core please ensure that your package manager didn't install any duplicates of it. You may deduplicate it manually using npx yarn-deduplicate (for Yarn) or npm dedupe (for npm), by @kitten (See #1357)gql tag function helper to @urql/core. This behaves similarly to graphql-tag but only warns about locally duplicated fragment names rather than globally. It also primes @urql/core's key cache with the parsed DocumentNode, by @kitten (See #1187)suspense: false to options when executeQuery is called explicitly, by @kitten (See #1181)useSource in a render update. This was previously then causing us to subscribe to an outdated source in useEffect since the updated source would be ignored by the time we reach useEffect in useSource, by @kitten (See #1157)and@urql/preact@1.4.0` but regressed in the patches afterwards that were aimed at fixing server-side Suspense, by @kitten (See #1142)suspenseExchange and uncached results are loaded consistently. As part of this work, the Client itself does now never throw Suspense promises anymore, which is functionality that either way has no place outside of the React/Preact bindings, by @kitten (See #1123)TypedDocumentNode to infer the type of the OperationResult and Operation for all methods, functions, and hooks that either directly or indirectly accept a DocumentNode. See graphql-typed-document-node and the corresponding blog post for more information., by @kitten (See #1113)useSource hooks which powers useQuery and useSubscription to improve various edge case behaviour. This will not change the behaviour of these hooks dramatically but avoid unnecessary state updates when any updates are obviously equivalent and the hook will furthermore improve continuation from mount to effects, which will fix cases where the state between the mounting and effect phase may slightly change, by @kitten (See #1104)Operation.operationName property in favor of Operation.kind. This name was
previously confusing as operationName was effectively referring to two different things. You can
safely upgrade to this new version, however to mute all deprecation warnings you will have to
upgrade all urql packages you use. If you have custom exchanges that spread operations, please
use the new makeOperation helper
function instead, by @bkonkle (See #1045)cache-and-network to work, we're pushing another patch that now forcefully bumps everyone to the
new version that includes this fix, by @kitten (See #684)package.json:main instead of module when an .mjs file imports a package, by @JoviDeCroock (See #642).mjs files and fails to resolve the new version, please double check your configuration for
Webpack, or similar tools, by @JoviDeCroock (See #637)@urql/core dependency minor version to ^1.10.1 for React, Preact and Svelte, by @JoviDeCroock (See #623)This patch fixes client-side suspense. While we wouldn't recommend its use
anymore, since suspense lends itself to prerendering instead of a loading
primitive, we'd like to ensure that suspense-mode works as expected in urql.
Also, as mentioned in v1.8.0's notes, please ensure that urql upgrades to
use wonka@^4.0.7 to avoid any issues. If your bundler or packager uses a
lower version with urql, you will see runtime errors.
useMemo for useCallback in hooks (see #504)toSuspenseSource helper (see #506)This patch fixes urql relying on a quirk in older versions of wonka where
shared sources wouldn't cascade cancellations, which they now do. This meant
that when an app goes from some queries/subscriptions to having none at all,
the exchange pipeline would be stopped completely.
This release doesn't change any major feature aspects, but comes with bugfixes
to our suspense and concurrent-mode handling. Due to an upgrade to wonka@^4.0.0
this is a minor version though.
In v1.6.0 we believed to
have solved all issues related to suspense and concurrent mode. However there were
still some remaining cases where concurrent mode behaved incorrectly. With the new
useOperator hook in react-wonka@2.0.0 we believe
to have now fixed all issues.
The initial mount of useQuery and useSubscription will now synchronously reflect
whatever urql returns, most of the times those will be cached results. Afterwards
all subsequent updates and fetches will be scheduled cooperatively with React on
an effect.
If you're using wonka for an exchange with urql you may want to upgrade to wonka@^4.0.5 soon.
You can still use the older v3.2.2 which will work with the new version (even in the same bundle),
unless you're making use of its subscribe, make, or makeSubject exports.
A migration guide can be found in the wonka docs.
This release splits our main package into two entrypoints. Importing from urql remains
unchanged, but internally this entrypoint uses urql/core, which doesn't contain any
React-related code. If you're building framework-agnostic libraries or apps without
React, you can now use urql/core directly.
originalError on GraphQLError instances (see #470)stringifyVariables not using .toJSON() which prevented Dates from being stringified, by @BjoernRave (see #485)urql/core without any React code included (see #424)client.query() (see #466)This fixes a potentially critical bug, where a component would enter an infinite rerender loop,
when another hook triggers an update. This may happen when multiple useQuery hooks are used in
a single component or when another state hook triggers a synchronous update.
client.query and client.mutation, by @ctrlplusb (see #456)useQuery entering an infinite loop during SSR when an update is triggered (see #459)This release comes with stability improvements for the useQuery and useSubscription hooks
when using suspense and concurrent mode. They should behave the same as before under normal
circumstances and continue to deliver the correct state on initial mount and updates.
The useQuery hook may however now trigger suspense updates when its inputs are changing,
as it should, instead of erroneously throwing a promise in useEffect.
The added stale: boolean flag on the hooks indicates whether a result is "stale".
useQuery will expose stale: true on results that are cached but will be updated
due to the use of cache-and-network.
We've also made some changes so that client.query() won't throw a promise, when suspense
mode is activated.
stale flag to OperationResult and hook results (see #449)useImmeditateEffect and useImmediateState with react-wonka derived state and effect (see #447)suspense flag to OperationContextfast-json-stable-stringify with embedded code (see #426)null data (see #437)This release finally adds shortcuts to imperatively make queries and mutations. They make it easier to quickly use the client programmatically, either with a Wonka source-based or Promise-based call.
// Call .query or .mutation which return Source<OperationResult>
const source = client.query(doc, vars);
const source = client.mutation(doc, vars);
// Call .toPromise() on the source to get Promise<OperationResult>
const promise = client.query(doc, vars).toPromise();
const promise = client.mutation(doc, vars).toPromise();This version also adds a useClient hook as a shortcut for useContext(Context).
We provide a default client that makes requests to /graphql. Since that has
confused users before, we now log a warning, when it's used.
client.query() and client.mutation() (see #405)useImmediateEffect for concurrent mode (see #418)Wonka.pipe using a Babel transform (see #419)useClient hook and warning when default client is used (see #420)This release adds "active teardowns" for operations, which means that an exchange can now send a teardown to cancel ongoing operations. The subscriptionsExchange for instance now ends ongoing subscriptions proactively if the server says that they've completed! This is also reflected as fetching: false in the useQuery and useSubscription hook.
We've also fixed a small issue with suspense and added all features from useQuery to useSubscription! This includes the pause argument and an executeSubscription function.
useSubscription (see #410)UseMutationResponse TypeScript type, by @jbugman (see #412)This release removes all metadata for the @urql/devtools extension from the core
urql package. This data will now be generated internally in the devtools exchange
itself. Please also upgrade to the latest @urql/devtools version if you're using
the extension.
This release has mainly been focused on minor refactors to keep the bundlesize low.
But it also introduces new features, like specifying a default requestPolicy and
a new polling option on useQuery!
This release also exports makeResult and makeErrorResult, which will reduce the
boilerplate code that you need for custom fetch exchanges.
debugExchange in production (see #375)requestPolicy option to Client to change the default request policy (see #376)graphql-tag and improve Operation.key hashing (see #383)networkLatency and source metadata from context, and delete useDevtoolsContext (see #387 and #388)pollInterval argument to useQuery, by @mxstbr (see #397)__typename from being added to the toplevel GraphQL documents (see #399)operationName field to fetch request body (see #401)This release comes with some important fixes and enhancements, which all address
certain edge-cases when using urql.
It fixes the cache-and-network request policy, which wouldn't always work correctly and issue another network request after resolving a response from the default cache. We also had a major bug in React Native environments where responses wouldn't ever be reflected in the useQuery hook's state. Lastly, you can now use extensions from your GraphQL servers and modify the OperationContext from the hooks options.
extensions key in GraphQL responses, by @adamscybot (see #355)cache-and-network request policy by adding operation flushing to the client (see #356)fetch option to the Client so it doesn't have to be polyfilled globally (see #357 and #359)useImmediateState for React Native environments (see #358)context option to all hooks to allow OperationContext to be changed dynamically (see #351)isClient option to ssrExchange in case suspense is activated on the client-side (see #369)A release focused on improving developer experience (in preparation for the upcoming devtools) as well as minor documentation improvements and bug fixes.
collectTypes method (see #343)This is a hotfix that patches a small regression from 1.1.2 where
useQuery would crash due to an incorrect teardown function from pause.
executeQuery dispose function when pause is set, by@JoviDeCroock (see #315)This patch fixes a small bug that usually manifests in development,
where the initial state would be incorrect after a fast response from
the GraphQL API. This used to lock the state into fetching: true
indefinitely in some cases.
dependencies (see #304)This release comes with two small patches. One being a critical fix, where cancelled requests would be erroneously deduped, which meant a previously cancelled query would never be fetched.
It also refactors our bundling process to transpile Object.assign to
restore IE11 support and reduce the amount of duplicate helper in our bundles.
useQuery's pause argument blocking explicit executeQuery calls (see #278)Object.assign transpilation for IE11 and refactor bundling (see #274)This release introduces support for server-side rendering. You can find out more about it by reading the new Basics section on how to set it up.
This version now also requires a version of React supporting hooks! (>= 16.8.0)
We unfortunately forgot to correct the peerDependencies entries in our v1.0.0 release.
create-react-context and bump React peer dependency (see #252)Query, Mutation, and Subscription componentsuseQuery wouldn't update or teardown correctly (see #243)pause prop/option to useQuery and Query (see #237)MutationProps types for TS typings, by @mxstbr (see #236)Use*Args types for TS typings, by @mxstbr (see #235)cachExchange where already deleted keys where being accessed (see #223)cacheExchange not forwarding teardowns correctly, which lead to unnecessary/outdated queries being executed, by @federicobadini (see #222)GraphQLRequest to always pass on a parsed GraphQL DocumentNode instead of just a string, which reduces work (see #221)Omit<T, K> (see #220)__typename not being extracted from responses correctly, which broke cachingfetchOptions being called in the client instead of the fetchExchangeCombinedError to actually extend Error and rehydrate GraphQLError instancesexecuteMutation prop not accepting any generics typesvariables were only compared using reference equality, leading to
infinite rerendersgraphql-tag / DocumentNode usage; Operations' queries can now be DocumentNodeshttps://github.com/FormidableLabs/urql/compare/v1.0.4...v1.0.5
Since the entire library has been rewritten for v1.0.0, no changes are listed here!
urql v1 is more customisable than ever with "Exchanges", which
allow you to change every aspect of how urql works.