@mearie/solid 0.3.5 → 0.4.0
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 +18 -7
- package/dist/index.mjs +19 -8
- package/package.json +5 -3
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
let _mearie_core = require("@mearie/core");
|
|
3
3
|
let solid_js = require("solid-js");
|
|
4
|
+
let solid_js_store = require("solid-js/store");
|
|
4
5
|
let _mearie_core_stream = require("@mearie/core/stream");
|
|
5
6
|
|
|
6
7
|
//#region src/client-provider.tsx
|
|
@@ -19,7 +20,7 @@ const useClient = () => {
|
|
|
19
20
|
const createQuery = ((query, variables, options) => {
|
|
20
21
|
const client = useClient();
|
|
21
22
|
const initialOpts = options?.();
|
|
22
|
-
const [data, setData] = (0,
|
|
23
|
+
const [data, setData] = (0, solid_js_store.createStore)({ value: initialOpts?.initialData });
|
|
23
24
|
const [loading, setLoading] = (0, solid_js.createSignal)(!initialOpts?.skip && !initialOpts?.initialData);
|
|
24
25
|
const [error, setError] = (0, solid_js.createSignal)();
|
|
25
26
|
const [metadata, setMetadata] = (0, solid_js.createSignal)();
|
|
@@ -40,7 +41,12 @@ const createQuery = ((query, variables, options) => {
|
|
|
40
41
|
setError(new _mearie_core.AggregatedError(result.errors));
|
|
41
42
|
setLoading(false);
|
|
42
43
|
} else {
|
|
43
|
-
|
|
44
|
+
const patches = result.metadata?.cache?.patches;
|
|
45
|
+
if (patches) setData("value", (0, solid_js_store.produce)((draft) => {
|
|
46
|
+
const root = (0, _mearie_core.applyPatchesMutable)(draft, patches);
|
|
47
|
+
if (root !== void 0) return root;
|
|
48
|
+
}));
|
|
49
|
+
else setData("value", (0, solid_js_store.reconcile)(result.data));
|
|
44
50
|
setLoading(false);
|
|
45
51
|
setError(void 0);
|
|
46
52
|
}
|
|
@@ -57,7 +63,7 @@ const createQuery = ((query, variables, options) => {
|
|
|
57
63
|
});
|
|
58
64
|
return {
|
|
59
65
|
get data() {
|
|
60
|
-
return data
|
|
66
|
+
return data.value;
|
|
61
67
|
},
|
|
62
68
|
get loading() {
|
|
63
69
|
return loading();
|
|
@@ -179,18 +185,23 @@ const createFragment = ((fragment, fragmentRef, options) => {
|
|
|
179
185
|
initialData = result.data;
|
|
180
186
|
initialMetadata = result.metadata;
|
|
181
187
|
}
|
|
182
|
-
const [data, setData] = (0,
|
|
188
|
+
const [data, setData] = (0, solid_js_store.createStore)({ value: initialData });
|
|
183
189
|
const [metadata, setMetadata] = (0, solid_js.createSignal)(initialMetadata);
|
|
184
190
|
(0, solid_js.createEffect)(() => {
|
|
185
191
|
const currentRef = fragmentRef();
|
|
186
192
|
if (currentRef == null) {
|
|
187
|
-
setData(()
|
|
193
|
+
setData("value", (0, solid_js_store.reconcile)(null));
|
|
188
194
|
setMetadata(void 0);
|
|
189
195
|
return;
|
|
190
196
|
}
|
|
191
197
|
const unsubscribe = (0, _mearie_core_stream.pipe)(client.executeFragment(fragment, currentRef, options?.()), (0, _mearie_core_stream.subscribe)({ next: (result) => {
|
|
192
198
|
setMetadata(result.metadata);
|
|
193
|
-
|
|
199
|
+
const patches = result.metadata?.cache?.patches;
|
|
200
|
+
if (patches) setData("value", (0, solid_js_store.produce)((draft) => {
|
|
201
|
+
const root = (0, _mearie_core.applyPatchesMutable)(draft, patches);
|
|
202
|
+
if (root !== void 0) return root;
|
|
203
|
+
}));
|
|
204
|
+
else if (result.data !== void 0) setData("value", (0, solid_js_store.reconcile)(result.data));
|
|
194
205
|
} }));
|
|
195
206
|
(0, solid_js.onCleanup)(() => {
|
|
196
207
|
unsubscribe();
|
|
@@ -198,7 +209,7 @@ const createFragment = ((fragment, fragmentRef, options) => {
|
|
|
198
209
|
});
|
|
199
210
|
return {
|
|
200
211
|
get data() {
|
|
201
|
-
return data
|
|
212
|
+
return data.value;
|
|
202
213
|
},
|
|
203
214
|
get metadata() {
|
|
204
215
|
return metadata();
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { AggregatedError } from "@mearie/core";
|
|
1
|
+
import { AggregatedError, applyPatchesMutable } from "@mearie/core";
|
|
2
2
|
import { createContext, createEffect, createSignal, onCleanup, untrack, useContext } from "solid-js";
|
|
3
|
+
import { createStore, produce, reconcile } from "solid-js/store";
|
|
3
4
|
import { collect, peek, pipe, subscribe, take } from "@mearie/core/stream";
|
|
4
5
|
|
|
5
6
|
export * from "@mearie/core"
|
|
@@ -20,7 +21,7 @@ const useClient = () => {
|
|
|
20
21
|
const createQuery = ((query, variables, options) => {
|
|
21
22
|
const client = useClient();
|
|
22
23
|
const initialOpts = options?.();
|
|
23
|
-
const [data, setData] =
|
|
24
|
+
const [data, setData] = createStore({ value: initialOpts?.initialData });
|
|
24
25
|
const [loading, setLoading] = createSignal(!initialOpts?.skip && !initialOpts?.initialData);
|
|
25
26
|
const [error, setError] = createSignal();
|
|
26
27
|
const [metadata, setMetadata] = createSignal();
|
|
@@ -41,7 +42,12 @@ const createQuery = ((query, variables, options) => {
|
|
|
41
42
|
setError(new AggregatedError(result.errors));
|
|
42
43
|
setLoading(false);
|
|
43
44
|
} else {
|
|
44
|
-
|
|
45
|
+
const patches = result.metadata?.cache?.patches;
|
|
46
|
+
if (patches) setData("value", produce((draft) => {
|
|
47
|
+
const root = applyPatchesMutable(draft, patches);
|
|
48
|
+
if (root !== void 0) return root;
|
|
49
|
+
}));
|
|
50
|
+
else setData("value", reconcile(result.data));
|
|
45
51
|
setLoading(false);
|
|
46
52
|
setError(void 0);
|
|
47
53
|
}
|
|
@@ -58,7 +64,7 @@ const createQuery = ((query, variables, options) => {
|
|
|
58
64
|
});
|
|
59
65
|
return {
|
|
60
66
|
get data() {
|
|
61
|
-
return data
|
|
67
|
+
return data.value;
|
|
62
68
|
},
|
|
63
69
|
get loading() {
|
|
64
70
|
return loading();
|
|
@@ -180,18 +186,23 @@ const createFragment = ((fragment, fragmentRef, options) => {
|
|
|
180
186
|
initialData = result.data;
|
|
181
187
|
initialMetadata = result.metadata;
|
|
182
188
|
}
|
|
183
|
-
const [data, setData] =
|
|
189
|
+
const [data, setData] = createStore({ value: initialData });
|
|
184
190
|
const [metadata, setMetadata] = createSignal(initialMetadata);
|
|
185
191
|
createEffect(() => {
|
|
186
192
|
const currentRef = fragmentRef();
|
|
187
193
|
if (currentRef == null) {
|
|
188
|
-
setData((
|
|
194
|
+
setData("value", reconcile(null));
|
|
189
195
|
setMetadata(void 0);
|
|
190
196
|
return;
|
|
191
197
|
}
|
|
192
198
|
const unsubscribe = pipe(client.executeFragment(fragment, currentRef, options?.()), subscribe({ next: (result) => {
|
|
193
199
|
setMetadata(result.metadata);
|
|
194
|
-
|
|
200
|
+
const patches = result.metadata?.cache?.patches;
|
|
201
|
+
if (patches) setData("value", produce((draft) => {
|
|
202
|
+
const root = applyPatchesMutable(draft, patches);
|
|
203
|
+
if (root !== void 0) return root;
|
|
204
|
+
}));
|
|
205
|
+
else if (result.data !== void 0) setData("value", reconcile(result.data));
|
|
195
206
|
} }));
|
|
196
207
|
onCleanup(() => {
|
|
197
208
|
unsubscribe();
|
|
@@ -199,7 +210,7 @@ const createFragment = ((fragment, fragmentRef, options) => {
|
|
|
199
210
|
});
|
|
200
211
|
return {
|
|
201
212
|
get data() {
|
|
202
|
-
return data
|
|
213
|
+
return data.value;
|
|
203
214
|
},
|
|
204
215
|
get metadata() {
|
|
205
216
|
return metadata();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mearie/solid",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Type-safe, zero-overhead GraphQL client",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
@@ -52,12 +52,14 @@
|
|
|
52
52
|
"README.md"
|
|
53
53
|
],
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@mearie/core": "0.
|
|
55
|
+
"@mearie/core": "0.6.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
+
"happy-dom": "^20.8.3",
|
|
58
59
|
"solid-js": "^1.9.11",
|
|
59
60
|
"tsdown": "^0.20.3",
|
|
60
|
-
"typescript": "^5.9.3"
|
|
61
|
+
"typescript": "^5.9.3",
|
|
62
|
+
"vite-plugin-solid": "^2.11.10"
|
|
61
63
|
},
|
|
62
64
|
"peerDependencies": {
|
|
63
65
|
"solid-js": "^1.8.0"
|