@mearie/react 0.3.5 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -45,7 +45,9 @@ const useQuery = ((query, variables, options) => {
45
45
  setError(new _mearie_core.AggregatedError(result.errors));
46
46
  setLoading(false);
47
47
  } else {
48
- setData(result.data);
48
+ const patches = result.metadata?.cache?.patches;
49
+ if (patches) setData((prev) => (0, _mearie_core.applyPatchesImmutable)(prev, patches));
50
+ else setData(result.data);
49
51
  setLoading(false);
50
52
  setError(void 0);
51
53
  }
@@ -176,8 +178,14 @@ const useFragment = ((fragment, fragmentRef, options) => {
176
178
  return () => {};
177
179
  }
178
180
  return (0, _mearie_core_stream.pipe)(client.executeFragment(fragment, fragmentRef, options), (0, _mearie_core_stream.subscribe)({ next: (result) => {
179
- if (result.errors && result.errors.length > 0) throw new _mearie_core.AggregatedError(result.errors);
180
- storeRef.current = {
181
+ const patches = result.metadata?.cache?.patches;
182
+ if (patches) {
183
+ const prevData = storeRef.current?.data;
184
+ storeRef.current = {
185
+ data: (0, _mearie_core.applyPatchesImmutable)(prevData, patches),
186
+ metadata: result.metadata
187
+ };
188
+ } else if (result.data !== void 0) storeRef.current = {
181
189
  data: result.data,
182
190
  metadata: result.metadata
183
191
  };
@@ -193,7 +201,7 @@ const useFragment = ((fragment, fragmentRef, options) => {
193
201
  if (fragmentRef == null) return NULL_STORE;
194
202
  if (storeRef.current === void 0) {
195
203
  const result = (0, _mearie_core_stream.pipe)(client.executeFragment(fragment, fragmentRef, options), _mearie_core_stream.peek);
196
- if (result.errors && result.errors.length > 0) throw new _mearie_core.AggregatedError(result.errors);
204
+ if (result.data === void 0) throw new Error("Fragment data not found");
197
205
  storeRef.current = {
198
206
  data: result.data,
199
207
  metadata: result.metadata
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { AggregatedError, stringify } from "@mearie/core";
1
+ import { AggregatedError, applyPatchesImmutable, stringify } from "@mearie/core";
2
2
  import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
3
3
  import { jsx } from "react/jsx-runtime";
4
4
  import { collect, peek, pipe, subscribe, take } from "@mearie/core/stream";
@@ -46,7 +46,9 @@ const useQuery = ((query, variables, options) => {
46
46
  setError(new AggregatedError(result.errors));
47
47
  setLoading(false);
48
48
  } else {
49
- setData(result.data);
49
+ const patches = result.metadata?.cache?.patches;
50
+ if (patches) setData((prev) => applyPatchesImmutable(prev, patches));
51
+ else setData(result.data);
50
52
  setLoading(false);
51
53
  setError(void 0);
52
54
  }
@@ -177,8 +179,14 @@ const useFragment = ((fragment, fragmentRef, options) => {
177
179
  return () => {};
178
180
  }
179
181
  return pipe(client.executeFragment(fragment, fragmentRef, options), subscribe({ next: (result) => {
180
- if (result.errors && result.errors.length > 0) throw new AggregatedError(result.errors);
181
- storeRef.current = {
182
+ const patches = result.metadata?.cache?.patches;
183
+ if (patches) {
184
+ const prevData = storeRef.current?.data;
185
+ storeRef.current = {
186
+ data: applyPatchesImmutable(prevData, patches),
187
+ metadata: result.metadata
188
+ };
189
+ } else if (result.data !== void 0) storeRef.current = {
182
190
  data: result.data,
183
191
  metadata: result.metadata
184
192
  };
@@ -194,7 +202,7 @@ const useFragment = ((fragment, fragmentRef, options) => {
194
202
  if (fragmentRef == null) return NULL_STORE;
195
203
  if (storeRef.current === void 0) {
196
204
  const result = pipe(client.executeFragment(fragment, fragmentRef, options), peek);
197
- if (result.errors && result.errors.length > 0) throw new AggregatedError(result.errors);
205
+ if (result.data === void 0) throw new Error("Fragment data not found");
198
206
  storeRef.current = {
199
207
  data: result.data,
200
208
  metadata: result.metadata
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mearie/react",
3
- "version": "0.3.5",
3
+ "version": "0.4.1",
4
4
  "description": "Type-safe, zero-overhead GraphQL client",
5
5
  "keywords": [
6
6
  "graphql",
@@ -52,11 +52,15 @@
52
52
  "README.md"
53
53
  ],
54
54
  "dependencies": {
55
- "@mearie/core": "0.5.2"
55
+ "@mearie/core": "0.6.1"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/react": "^19.2.14",
59
+ "@types/react-dom": "^19.2.3",
60
+ "@vitejs/plugin-react": "^5.1.4",
61
+ "happy-dom": "^20.8.3",
59
62
  "react": "^19.2.4",
63
+ "react-dom": "^19.2.4",
60
64
  "tsdown": "^0.20.3",
61
65
  "typescript": "^5.9.3"
62
66
  },