@mearie/vue 0.3.4 → 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 CHANGED
@@ -19,16 +19,19 @@ const useClient = () => {
19
19
  const useQuery = ((query, variables, options) => {
20
20
  const client = useClient();
21
21
  const initialOpts = (0, vue.toValue)(options);
22
- const data = (0, vue.ref)(initialOpts?.initialData);
22
+ const data = (0, vue.shallowRef)(initialOpts?.initialData ? (0, vue.reactive)(initialOpts.initialData) : void 0);
23
23
  const loading = (0, vue.ref)(!initialOpts?.skip && !initialOpts?.initialData);
24
24
  const error = (0, vue.ref)(void 0);
25
25
  const metadata = (0, vue.ref)();
26
26
  let unsubscribe = null;
27
27
  let initialized = false;
28
- const execute = () => {
28
+ const execute = (force = false) => {
29
29
  unsubscribe?.();
30
- if ((0, vue.toValue)(options)?.skip) return;
31
- if (!initialized && initialOpts?.initialData) loading.value = true;
30
+ if (!force && (0, vue.toValue)(options)?.skip) {
31
+ loading.value = false;
32
+ return;
33
+ }
34
+ if (initialized || !initialOpts?.initialData) loading.value = true;
32
35
  initialized = true;
33
36
  error.value = void 0;
34
37
  unsubscribe = (0, _mearie_core_stream.pipe)(client.executeQuery(query, (0, vue.toValue)(variables), (0, vue.toValue)(options)), (0, _mearie_core_stream.subscribe)({ next: (result) => {
@@ -37,12 +40,17 @@ const useQuery = ((query, variables, options) => {
37
40
  error.value = new _mearie_core.AggregatedError(result.errors);
38
41
  loading.value = false;
39
42
  } else {
40
- data.value = result.data;
43
+ const patches = result.metadata?.cache?.patches;
44
+ if (patches) {
45
+ const root = (0, _mearie_core.applyPatchesMutable)(data.value, patches);
46
+ if (root !== void 0) data.value = (0, vue.reactive)(root);
47
+ } else data.value = (0, vue.reactive)(result.data);
41
48
  loading.value = false;
42
49
  error.value = void 0;
43
50
  }
44
51
  } }));
45
52
  };
53
+ const refetch = () => execute(true);
46
54
  (0, vue.watchEffect)((onCleanup) => {
47
55
  execute();
48
56
  onCleanup(() => {
@@ -54,7 +62,7 @@ const useQuery = ((query, variables, options) => {
54
62
  loading,
55
63
  error,
56
64
  metadata,
57
- refetch: execute
65
+ refetch
58
66
  };
59
67
  });
60
68
 
@@ -154,8 +162,8 @@ const useFragment = ((fragment, fragmentRef, ...[options]) => {
154
162
  initialData = result.data;
155
163
  initialMetadata = result.metadata;
156
164
  }
157
- const data = (0, vue.ref)(initialData);
158
- const metadata = (0, vue.ref)(initialMetadata);
165
+ const data = (0, vue.shallowRef)(initialData == null ? initialData : (0, vue.reactive)(initialData));
166
+ const metadata = (0, vue.shallowRef)(initialMetadata);
159
167
  (0, vue.watchEffect)((onCleanup) => {
160
168
  const currentRef = (0, vue.toValue)(fragmentRef);
161
169
  if (currentRef == null) {
@@ -165,7 +173,11 @@ const useFragment = ((fragment, fragmentRef, ...[options]) => {
165
173
  }
166
174
  const unsubscribe = (0, _mearie_core_stream.pipe)(client.executeFragment(fragment, currentRef, (0, vue.toValue)(options)), (0, _mearie_core_stream.subscribe)({ next: (result) => {
167
175
  metadata.value = result.metadata;
168
- if (result.data !== void 0) data.value = result.data;
176
+ const patches = result.metadata?.cache?.patches;
177
+ if (patches) {
178
+ const root = (0, _mearie_core.applyPatchesMutable)(data.value, patches);
179
+ if (root !== void 0) data.value = (0, vue.reactive)(root);
180
+ } else if (result.data !== void 0) data.value = (0, vue.reactive)(result.data);
169
181
  } }));
170
182
  onCleanup(() => unsubscribe());
171
183
  });
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { AggregatedError } from "@mearie/core";
2
- import { inject, ref, toValue, watchEffect } from "vue";
1
+ import { AggregatedError, applyPatchesMutable } from "@mearie/core";
2
+ import { inject, reactive, ref, shallowRef, toValue, watchEffect } from "vue";
3
3
  import { collect, peek, pipe, subscribe, take } from "@mearie/core/stream";
4
4
 
5
5
  export * from "@mearie/core"
@@ -20,16 +20,19 @@ const useClient = () => {
20
20
  const useQuery = ((query, variables, options) => {
21
21
  const client = useClient();
22
22
  const initialOpts = toValue(options);
23
- const data = ref(initialOpts?.initialData);
23
+ const data = shallowRef(initialOpts?.initialData ? reactive(initialOpts.initialData) : void 0);
24
24
  const loading = ref(!initialOpts?.skip && !initialOpts?.initialData);
25
25
  const error = ref(void 0);
26
26
  const metadata = ref();
27
27
  let unsubscribe = null;
28
28
  let initialized = false;
29
- const execute = () => {
29
+ const execute = (force = false) => {
30
30
  unsubscribe?.();
31
- if (toValue(options)?.skip) return;
32
- if (!initialized && initialOpts?.initialData) loading.value = true;
31
+ if (!force && toValue(options)?.skip) {
32
+ loading.value = false;
33
+ return;
34
+ }
35
+ if (initialized || !initialOpts?.initialData) loading.value = true;
33
36
  initialized = true;
34
37
  error.value = void 0;
35
38
  unsubscribe = pipe(client.executeQuery(query, toValue(variables), toValue(options)), subscribe({ next: (result) => {
@@ -38,12 +41,17 @@ const useQuery = ((query, variables, options) => {
38
41
  error.value = new AggregatedError(result.errors);
39
42
  loading.value = false;
40
43
  } else {
41
- data.value = result.data;
44
+ const patches = result.metadata?.cache?.patches;
45
+ if (patches) {
46
+ const root = applyPatchesMutable(data.value, patches);
47
+ if (root !== void 0) data.value = reactive(root);
48
+ } else data.value = reactive(result.data);
42
49
  loading.value = false;
43
50
  error.value = void 0;
44
51
  }
45
52
  } }));
46
53
  };
54
+ const refetch = () => execute(true);
47
55
  watchEffect((onCleanup) => {
48
56
  execute();
49
57
  onCleanup(() => {
@@ -55,7 +63,7 @@ const useQuery = ((query, variables, options) => {
55
63
  loading,
56
64
  error,
57
65
  metadata,
58
- refetch: execute
66
+ refetch
59
67
  };
60
68
  });
61
69
 
@@ -155,8 +163,8 @@ const useFragment = ((fragment, fragmentRef, ...[options]) => {
155
163
  initialData = result.data;
156
164
  initialMetadata = result.metadata;
157
165
  }
158
- const data = ref(initialData);
159
- const metadata = ref(initialMetadata);
166
+ const data = shallowRef(initialData == null ? initialData : reactive(initialData));
167
+ const metadata = shallowRef(initialMetadata);
160
168
  watchEffect((onCleanup) => {
161
169
  const currentRef = toValue(fragmentRef);
162
170
  if (currentRef == null) {
@@ -166,7 +174,11 @@ const useFragment = ((fragment, fragmentRef, ...[options]) => {
166
174
  }
167
175
  const unsubscribe = pipe(client.executeFragment(fragment, currentRef, toValue(options)), subscribe({ next: (result) => {
168
176
  metadata.value = result.metadata;
169
- if (result.data !== void 0) data.value = result.data;
177
+ const patches = result.metadata?.cache?.patches;
178
+ if (patches) {
179
+ const root = applyPatchesMutable(data.value, patches);
180
+ if (root !== void 0) data.value = reactive(root);
181
+ } else if (result.data !== void 0) data.value = reactive(result.data);
170
182
  } }));
171
183
  onCleanup(() => unsubscribe());
172
184
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mearie/vue",
3
- "version": "0.3.4",
3
+ "version": "0.4.0",
4
4
  "description": "Type-safe, zero-overhead GraphQL client",
5
5
  "keywords": [
6
6
  "graphql",
@@ -52,9 +52,11 @@
52
52
  "README.md"
53
53
  ],
54
54
  "dependencies": {
55
- "@mearie/core": "0.5.2"
55
+ "@mearie/core": "0.6.0"
56
56
  },
57
57
  "devDependencies": {
58
+ "@vitejs/plugin-vue": "^6.0.4",
59
+ "happy-dom": "^20.8.3",
58
60
  "tsdown": "^0.20.3",
59
61
  "typescript": "^5.9.3",
60
62
  "vue": "^3.5.29"