Skip to content
On this page

v0.5 Chew Lan

Chew Lan

Photo by Maria Goroshko

Why Chew Lan?

Chew Lan is a large artificial lake in the Khao Sok National Park and one of the most calm places in the world. Plenty of APIs in Farfetched were invented there.

update operator is there! It allows you to update Query on top of Mutation result 👇

ts
import { update } from '@farfetched/core';

update(postQuery, {
  on: editPostTitleMutation,
  by: {
    success(state) {
      const oldPost = state.query.result;
      const editions = state.mutation.params;

      return {
        result: { ...oldPost, title: editions.title },
        refetch: true,
      };
    },
  },
});

It also includes a couple of minor improvements and bug fixes. Read the full changelog below.

Migration guide

Since v0.5, Farfetched supports @@unitShape protocol, so you can use useUnit from effector-react and effector-solid to subscribe to custom entities like Query and Mutation.

Do not use @farfetched/react

Package @farfetched/react is deprecated, just use useUnit from effector-react instead of useQuery and useMutation 🪄

tsx
import { useQuery, useMutation } from '@farfetched/react'; 
import { useUnit } from 'effector-react'; 

function User() {
  const { data: user } = useQuery(userQuery); 
  const { data: user } = useUnit(userQuery); 

  const { start: deleteAccount } = useMutation(deleteAccountMutation); 
  const { start: deleteAccount } = useUnit(deleteAccountMutation); 

  return (
    <div>
      <p>Name: {user.name}</p>
      <button onClick={deleteAccount}>Delete my account</button>
    </div>
  );
}

Do not use useMutation from @farfetched/solid

Function useMutation from @farfetched/solid is deprecated, just use useUnit from effector-solid instead 🪄

tsx
import {
  createQueryResource,
  useMutation, 
} from '@farfetched/solid';
import { useUnit } from 'effector-react'; 

function User() {
  const [user] = createQueryResource(userQuery);

  const { start: deleteAccount } = useMutation(deleteAccountMutation); 
  const { start: deleteAccount } = useUnit(deleteAccountMutation); 

  return (
    <Suspense fallback={<p>Loading...</p>}>
      <div>
        <p>Name: {user().name}</p>
        <button onClick={deleteAccount}>Delete my account</button>
      </div>
    </Suspense>
  );
}

TIP

Q: Why createQueryResource is still there?

A: Because @@unitShape protocol supports only shapes of units, not custom operations like binding Query with Suspense of Solid.

Full changelog

0.5.1

@farfetched/core

Patch Changes

  • 2ad92fb: Do not use value from cache on refetch after update

0.5.0

@farfetched/react

Minor Changes

  • e0802dd: Deprecate @farfetched/react in favour of @@unitShape protocol
@farfetched/core

Minor Changes

  • 57abab2: Add config concurrency.strategy for createJsonQuery factory
  • dcbdcaa: Support more formats in Time
  • e914ba2: Add operator update to connect Query and Mutation
  • 127f78a: Pass params of source Queries to fn in connectQuery
  • e0802dd: Support @@unitShape protocol of Effector

Patch Changes

  • e52935e: Do not stop Query after trying to cache entry with invalid key
  • 41096d5: Decreased number of cache misses
  • d32d69f: Skip in-flight Query and Mutation while disabling
  • 41096d5: Do not try to serialize unserializable params during cache
@farfetched/solid

Minor Changes

  • e0802dd: Deprecate useMutation in favour of @@unitShape protocol

Released under the MIT License.