Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Releases: openapi-ts/swr-openapi

v5.0.0

11 Sep 18:37
Compare
Choose a tag to compare

Overview of Changes

  • Rewrote APIs to use latest openapi-fetch types.
  • Added useImmutable and useMutate hooks.
  • Broke apart createHooks into separate builder functions.
  • Added support for optional fetch option arguments.
  • Wrote comprehensive tests for both runtime behavior and type checking.
  • Wrote brand-new README documentation detailing new APIs.

See how to migrate from v4 below 👇

Breaking Changes

  • Removed CommonJS support (now ESM-only).
  • Removed global configuration function.
  • Replaced createHooks with separate builder functions.
  • Replaced matchKeyComparator with useMutate.
  • Renamed and refactored RequestTypesTypesForRequest.
  • Fixed internal types that broke from breaking changes in openapi-fetch.

Migration from v4

Imports

Replace createHooks calls with createQueryHook, createInfiniteHook, and createImmutableHook as needed.

import createClient from "openapi-fetch";
-import { createHooks } from "swr-openapi";
+import { createQueryHook, createInfiniteHook } from "swr-openapi";

const client = createClient(/* */);

-const { 
-  use: useSandwich, 
-  useInfinite: useSandwichInfinite 
-} = createHooks(client, "sandwich-api");
+export const useSandwich = createQueryHook(client, "sandwich-api");
+export const useSandwichInfinite = createInfiniteHook(client, "sandwich-api");

Fetch Options

For requests made that don't have required fetch options (like a path parameter), feel free to remove empty init arguments like this, as they are no longer required!

-const { data } = useQuery('/some/path', {});
+const { data } = useQuery('/some/path');

Key Matchers

Remove applySwrOpenApiConfiguration and define a useMutate hook using createMutateHook:

import createClient from "openapi-fetch";
import { isMatch } from "lodash";
-import { applySwrOpenApiConfiguration, createHooks } from "swr-openapi";
+import { createMutateHook } from "swr-openapi";

const client = createClient(/* */);

-applySwrOpenApiConfiguration({ matchKeyComparator: isMatch });

-export { matchKey } = createHooks(client, "unique-prefix");
+export const useMutate = createMutateHook(
+  client,
+  prefix,
+  isMatch
+);

To replace matchKey in consumers, call useMutate and invoke the callback like this:

-import { useSWRConfig } from "swr";
-import { matchKey } from "./api-clients";
+import { useMutate } from "./api-clients";  

function MyComponent() {
  // ...

-  const { mutate } = useSWRConfig();
+  const mutate = useMutate();

  const save = async () => {
    // ...
    await mutate(
-     matchKey("/some/path", { params: { query: { some: "item" } } }),
+     ["/some/path", { params: { query: { some: "item" } } }],
      { some: "data" },
    );
  };

  // ...
}

ESM in Next.js

If using Next.js in a non-ESM project, add swr-openapi to the transpilePackages array in your Next.js config file. This should take care of transpilation automatically, as well as transforming in Jest (if you use next/jest).


v4.1.2...v5.0.0

v5.0.0-rc.15

11 Sep 17:26
Compare
Choose a tag to compare
v5.0.0-rc.15 Pre-release
Pre-release
  • Add links to swr documentation 936306b

v5.0.0-rc.14...v5.0.0-rc.15

v5.0.0-rc.8

10 Sep 16:21
Compare
Choose a tag to compare
v5.0.0-rc.8 Pre-release
Pre-release

v5.0.0-rc.7

10 Sep 15:58
Compare
Choose a tag to compare
v5.0.0-rc.7 Pre-release
Pre-release

v5.0.0-rc.6

10 Sep 15:50
Compare
Choose a tag to compare
v5.0.0-rc.6 Pre-release
Pre-release

v5.0.0-rc.5...v5.0.0-rc.6

v5.0.0-rc.14

10 Sep 23:12
Compare
Choose a tag to compare
v5.0.0-rc.14 Pre-release
Pre-release
  • Include prefix in debug values b9bcba5

v5.0.0-rc.13...v5.0.0-rc.14

v5.0.0-rc.13

10 Sep 23:03
Compare
Choose a tag to compare
v5.0.0-rc.13 Pre-release
Pre-release
  • Add debug values 5b45135
  • Add memoization hooks bcd0b3e
  • Add key matcher docs 0574cf1
  • Add test for mutate promise types 07698a7
  • Add missing support for boolean mutate argument 01cad7a

v5.0.0-rc.12...v5.0.0-rc.13

v5.0.0-rc.12

10 Sep 22:01
Compare
Choose a tag to compare
v5.0.0-rc.12 Pre-release
Pre-release
  • Repair broken openapi-fetch types 5fbda5a

v5.0.0-rc.11...v5.0.0-rc.12

v5.0.0-rc.1

10 Sep 03:38
Compare
Choose a tag to compare
v5.0.0-rc.1 Pre-release
Pre-release

What's Changed

  • Add RequestTypes utility back.

Full Changelog: v5.0.0-rc.0...v5.0.0-rc.1

v5.0.0-rc.0

10 Sep 03:31
Compare
Choose a tag to compare
v5.0.0-rc.0 Pre-release
Pre-release

What's Changed

  • Add missing wrapper hooks and standardize APIs by @htunnicliff in #7

Full Changelog: v4.1.0...v5.0.0-rc.0