@mearie/vue 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
@@ -19,7 +19,7 @@ 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)();
@@ -40,7 +40,11 @@ const useQuery = ((query, variables, options) => {
40
40
  error.value = new _mearie_core.AggregatedError(result.errors);
41
41
  loading.value = false;
42
42
  } else {
43
- 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);
44
48
  loading.value = false;
45
49
  error.value = void 0;
46
50
  }
@@ -158,8 +162,8 @@ const useFragment = ((fragment, fragmentRef, ...[options]) => {
158
162
  initialData = result.data;
159
163
  initialMetadata = result.metadata;
160
164
  }
161
- const data = (0, vue.ref)(initialData);
162
- 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);
163
167
  (0, vue.watchEffect)((onCleanup) => {
164
168
  const currentRef = (0, vue.toValue)(fragmentRef);
165
169
  if (currentRef == null) {
@@ -169,7 +173,11 @@ const useFragment = ((fragment, fragmentRef, ...[options]) => {
169
173
  }
170
174
  const unsubscribe = (0, _mearie_core_stream.pipe)(client.executeFragment(fragment, currentRef, (0, vue.toValue)(options)), (0, _mearie_core_stream.subscribe)({ next: (result) => {
171
175
  metadata.value = result.metadata;
172
- 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);
173
181
  } }));
174
182
  onCleanup(() => unsubscribe());
175
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,7 +20,7 @@ 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();
@@ -41,7 +41,11 @@ const useQuery = ((query, variables, options) => {
41
41
  error.value = new AggregatedError(result.errors);
42
42
  loading.value = false;
43
43
  } else {
44
- 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);
45
49
  loading.value = false;
46
50
  error.value = void 0;
47
51
  }
@@ -159,8 +163,8 @@ const useFragment = ((fragment, fragmentRef, ...[options]) => {
159
163
  initialData = result.data;
160
164
  initialMetadata = result.metadata;
161
165
  }
162
- const data = ref(initialData);
163
- const metadata = ref(initialMetadata);
166
+ const data = shallowRef(initialData == null ? initialData : reactive(initialData));
167
+ const metadata = shallowRef(initialMetadata);
164
168
  watchEffect((onCleanup) => {
165
169
  const currentRef = toValue(fragmentRef);
166
170
  if (currentRef == null) {
@@ -170,7 +174,11 @@ const useFragment = ((fragment, fragmentRef, ...[options]) => {
170
174
  }
171
175
  const unsubscribe = pipe(client.executeFragment(fragment, currentRef, toValue(options)), subscribe({ next: (result) => {
172
176
  metadata.value = result.metadata;
173
- 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);
174
182
  } }));
175
183
  onCleanup(() => unsubscribe());
176
184
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mearie/vue",
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,9 +52,11 @@
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
+ "@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"