Skip to main content

What's new in 2.0

Mutations, subscriptions and new hooks for React make lazy loading, suspense, and other patterns much easier. Here's a breakdown of what's changed:

Improved performance#

Client-side#

Runtime speed has been dramatically increased, fetching data now scales much better - the largest queries will see the greatest benefit. The schema format has been simplified.

Build-time#

Types are now generated differently. You should see significant gains in TypeScript compiler performance.

Mutations#

Support for mutations has been added. They work very similarly to queries, using the mutation object instead.

Subscriptions#

Support for subscriptions is now here. You can build realtime user interfaces with GQless now.

Caching strategies and fetch policies#

Theres new support for caching strategies and persistence, that allow your queries to retrieve previously fetched data. It supports the stale-while-revalidate pattern as well as cache-and-network, cache-first, network-only and no-cache policies, and lets you configure how you want your cache to persist for cross-session persistence.

Normalized caching has also been improved.

Server-side Rendering#

Server-Side rendering (SSR) is now supported, which works great with Next.js. See React SSR for more

React Hooks#

The useQuery hook has been added, which you can use in replacement of the HoC

The new hooks include:

  • useTransactionQuery: Giving you access to loading state, polling, and more.
  • useLazyQuery: A query that can be triggered conditionally.
  • useRefetch: A hook that works alongside regular useQuery, letting your programatically make it refetch.
  • useMutation: More control over mutations with loading states.
  • useSubscription: Likewise, a hook for subscriptions.
  • useMetaState: Lets you hook into the fetch state of gqless and output errors.
  • useHydrateCache: For restoring SSR state to the client.

And the new helpers functions:

  • prepareQuery: Extract queries above components, letting you do fancier early-fetching on important queries.
  • prepareReactRender: Use before rendering React to trigger getting data.

Client configuration#

You can now configure options for the core-client and react integration. A retry option allows for failed queries to retry automatically.

File uploading#

File uploading is now supported, see here for more.

Last updated on by Sam Denty