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-sideRuntime 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-timeTypes are now generated differently. You should see significant gains in TypeScript compiler performance.
#
MutationsSupport for mutations has been added. They work very similarly to queries, using the mutation
object instead.
#
SubscriptionsSupport for subscriptions is now here. You can build realtime user interfaces with GQless now.
#
Caching strategies and fetch policiesTheres 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 RenderingServer-Side rendering (SSR) is now supported, which works great with Next.js. See React SSR for more
#
React HooksThe 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 configurationYou can now configure options for the core-client and react integration. A retry
option allows for failed queries to retry automatically.
#
File uploadingFile uploading is now supported, see here for more.