Skip to main content

New in 2.0

GQless 2 is a complete rewrite of version 1, fixing many of the outstanding issues and implementing large features like mutations and subscriptions, as well as many new hooks for React to make lazy loading, suspense, and other patterns easier.

Runtime Performance#

v2 is dramatically faster at fetching, especially with large amounts of data. This is due to re-doing how the schema is generated to avoid creating many intermediate objects. The larger your query result is, the better version 2 will perform compared to v1.

Typescript Performance#

v2 also redid how types are generated, avoiding type explosions that happened in v1. The types generated alongside your schema are now just types, rather than typed instances of classes. This flattens things quite a bit, and we've seen no performance issues, even on very large schemas .

Mutations#

v2 adds mutations support first class. They work very similarly to queries, using the mutation object.

Subscriptions#

v2 adds subscriptions support.

Caching strategies and fetch policies#

v2 adds caching strategies and persistence, that allow your queries to automatically resolve 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.

Built in normalized caching works as well, which will recognize the same object across different types of queries.

Server-side Rendering#

v2 adds Server-Side rendering (SSR) first-class support.

Check React Server-Side Rendering

React Hooks#

v2 removes the need to only use a higher order component, and lets you just use a simple useQuery hook for React.

Alongside that, there are many new hooks that handle common use cases:

  • 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.

As well as some helpers:

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

Revamped configuration#

v2 adds many new Core and React configuration options, with highlights including retry for retrying failed queries automatically.

Uploads#

v2 adds support for uploading files.

Last updated on by Nate Wienert