@mearie/vue 0.2.3 → 0.3.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 +26 -5
- package/dist/index.d.cts +16 -1
- package/dist/index.d.mts +16 -1
- package/dist/index.mjs +26 -5
- package/package.json +11 -4
package/dist/index.cjs
CHANGED
|
@@ -22,6 +22,7 @@ const useQuery = ((query, variables, options) => {
|
|
|
22
22
|
const data = (0, vue.ref)(initialOpts?.initialData);
|
|
23
23
|
const loading = (0, vue.ref)(!initialOpts?.skip && !initialOpts?.initialData);
|
|
24
24
|
const error = (0, vue.ref)(void 0);
|
|
25
|
+
const metadata = (0, vue.ref)();
|
|
25
26
|
let unsubscribe = null;
|
|
26
27
|
let initialized = false;
|
|
27
28
|
const execute = () => {
|
|
@@ -31,6 +32,7 @@ const useQuery = ((query, variables, options) => {
|
|
|
31
32
|
initialized = true;
|
|
32
33
|
error.value = void 0;
|
|
33
34
|
unsubscribe = (0, _mearie_core_stream.pipe)(client.executeQuery(query, (0, vue.toValue)(variables), (0, vue.toValue)(options)), (0, _mearie_core_stream.subscribe)({ next: (result) => {
|
|
35
|
+
metadata.value = result.metadata;
|
|
34
36
|
if (result.errors && result.errors.length > 0) {
|
|
35
37
|
error.value = new _mearie_core.AggregatedError(result.errors);
|
|
36
38
|
loading.value = false;
|
|
@@ -51,6 +53,7 @@ const useQuery = ((query, variables, options) => {
|
|
|
51
53
|
data,
|
|
52
54
|
loading,
|
|
53
55
|
error,
|
|
56
|
+
metadata,
|
|
54
57
|
refetch: execute
|
|
55
58
|
};
|
|
56
59
|
});
|
|
@@ -62,6 +65,7 @@ const useSubscription = (subscription, ...[variables, options]) => {
|
|
|
62
65
|
const data = (0, vue.ref)(void 0);
|
|
63
66
|
const loading = (0, vue.ref)(!(0, vue.toValue)(options)?.skip);
|
|
64
67
|
const error = (0, vue.ref)(void 0);
|
|
68
|
+
const metadata = (0, vue.ref)();
|
|
65
69
|
let unsubscribe = null;
|
|
66
70
|
const execute = () => {
|
|
67
71
|
unsubscribe?.();
|
|
@@ -69,6 +73,7 @@ const useSubscription = (subscription, ...[variables, options]) => {
|
|
|
69
73
|
loading.value = true;
|
|
70
74
|
error.value = void 0;
|
|
71
75
|
unsubscribe = (0, _mearie_core_stream.pipe)(client.executeSubscription(subscription, (0, vue.toValue)(variables), (0, vue.toValue)(options)), (0, _mearie_core_stream.subscribe)({ next: (result) => {
|
|
76
|
+
metadata.value = result.metadata;
|
|
72
77
|
if (result.errors && result.errors.length > 0) {
|
|
73
78
|
const err = new _mearie_core.AggregatedError(result.errors);
|
|
74
79
|
error.value = err;
|
|
@@ -91,7 +96,8 @@ const useSubscription = (subscription, ...[variables, options]) => {
|
|
|
91
96
|
return {
|
|
92
97
|
data,
|
|
93
98
|
loading,
|
|
94
|
-
error
|
|
99
|
+
error,
|
|
100
|
+
metadata
|
|
95
101
|
};
|
|
96
102
|
};
|
|
97
103
|
|
|
@@ -102,17 +108,21 @@ const useMutation = (mutation) => {
|
|
|
102
108
|
const data = (0, vue.ref)(void 0);
|
|
103
109
|
const loading = (0, vue.ref)(false);
|
|
104
110
|
const error = (0, vue.ref)(void 0);
|
|
111
|
+
const metadata = (0, vue.ref)();
|
|
105
112
|
const execute = async (variables, options) => {
|
|
106
113
|
loading.value = true;
|
|
107
114
|
error.value = void 0;
|
|
115
|
+
metadata.value = void 0;
|
|
108
116
|
try {
|
|
109
117
|
const result = await (0, _mearie_core_stream.pipe)(client.executeMutation(mutation, variables, options), (0, _mearie_core_stream.take)(1), _mearie_core_stream.collect);
|
|
110
118
|
if (result.errors && result.errors.length > 0) {
|
|
111
119
|
const err = new _mearie_core.AggregatedError(result.errors);
|
|
120
|
+
metadata.value = result.metadata;
|
|
112
121
|
error.value = err;
|
|
113
122
|
loading.value = false;
|
|
114
123
|
throw err;
|
|
115
124
|
}
|
|
125
|
+
metadata.value = result.metadata;
|
|
116
126
|
data.value = result.data;
|
|
117
127
|
loading.value = false;
|
|
118
128
|
return result.data;
|
|
@@ -125,7 +135,8 @@ const useMutation = (mutation) => {
|
|
|
125
135
|
return [execute, {
|
|
126
136
|
data,
|
|
127
137
|
loading,
|
|
128
|
-
error
|
|
138
|
+
error,
|
|
139
|
+
metadata
|
|
129
140
|
}];
|
|
130
141
|
};
|
|
131
142
|
|
|
@@ -135,27 +146,37 @@ const useFragment = ((fragment, fragmentRef, ...[options]) => {
|
|
|
135
146
|
const client = useClient();
|
|
136
147
|
const initialRef = (0, vue.toValue)(fragmentRef);
|
|
137
148
|
let initialData;
|
|
149
|
+
let initialMetadata;
|
|
138
150
|
if (initialRef == null) initialData = null;
|
|
139
151
|
else {
|
|
140
152
|
const result = (0, _mearie_core_stream.pipe)(client.executeFragment(fragment, initialRef, (0, vue.toValue)(options)), _mearie_core_stream.peek);
|
|
141
153
|
if (result.data === void 0) throw new Error("Fragment data not found");
|
|
142
154
|
initialData = result.data;
|
|
155
|
+
initialMetadata = result.metadata;
|
|
143
156
|
}
|
|
144
157
|
const data = (0, vue.ref)(initialData);
|
|
158
|
+
const metadata = (0, vue.ref)(initialMetadata);
|
|
145
159
|
(0, vue.watchEffect)((onCleanup) => {
|
|
146
160
|
const currentRef = (0, vue.toValue)(fragmentRef);
|
|
147
161
|
if (currentRef == null) {
|
|
148
162
|
data.value = null;
|
|
163
|
+
metadata.value = void 0;
|
|
149
164
|
return;
|
|
150
165
|
}
|
|
151
166
|
const unsubscribe = (0, _mearie_core_stream.pipe)(client.executeFragment(fragment, currentRef, (0, vue.toValue)(options)), (0, _mearie_core_stream.subscribe)({ next: (result) => {
|
|
167
|
+
metadata.value = result.metadata;
|
|
152
168
|
if (result.data !== void 0) data.value = result.data;
|
|
153
169
|
} }));
|
|
154
170
|
onCleanup(() => unsubscribe());
|
|
155
171
|
});
|
|
156
|
-
return {
|
|
157
|
-
|
|
158
|
-
|
|
172
|
+
return {
|
|
173
|
+
get data() {
|
|
174
|
+
return data.value;
|
|
175
|
+
},
|
|
176
|
+
get metadata() {
|
|
177
|
+
return metadata.value;
|
|
178
|
+
}
|
|
179
|
+
};
|
|
159
180
|
});
|
|
160
181
|
|
|
161
182
|
//#endregion
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AggregatedError, Artifact, Client, DataOf, FragmentOptions, FragmentRefs, MutationOptions, QueryOptions, SchemaMeta, SubscriptionOptions, VariablesOf } from "@mearie/core";
|
|
1
|
+
import { AggregatedError, Artifact, Client, DataOf, FragmentOptions, FragmentRefs, MutationOptions, OperationResult, QueryOptions, SchemaMeta, SubscriptionOptions, VariablesOf } from "@mearie/core";
|
|
2
2
|
import { App, MaybeRefOrGetter, Ref } from "vue";
|
|
3
3
|
export * from "@mearie/core";
|
|
4
4
|
|
|
@@ -19,32 +19,38 @@ type Query<T extends Artifact<'query'>> = {
|
|
|
19
19
|
data: Ref<undefined>;
|
|
20
20
|
loading: Ref<true>;
|
|
21
21
|
error: Ref<undefined>;
|
|
22
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
22
23
|
refetch: () => void;
|
|
23
24
|
} | {
|
|
24
25
|
data: Ref<DataOf<T>>;
|
|
25
26
|
loading: Ref<false>;
|
|
26
27
|
error: Ref<undefined>;
|
|
28
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
27
29
|
refetch: () => void;
|
|
28
30
|
} | {
|
|
29
31
|
data: Ref<DataOf<T> | undefined>;
|
|
30
32
|
loading: Ref<false>;
|
|
31
33
|
error: Ref<AggregatedError>;
|
|
34
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
32
35
|
refetch: () => void;
|
|
33
36
|
};
|
|
34
37
|
type DefinedQuery<T extends Artifact<'query'>> = {
|
|
35
38
|
data: Ref<DataOf<T>>;
|
|
36
39
|
loading: Ref<true>;
|
|
37
40
|
error: Ref<undefined>;
|
|
41
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
38
42
|
refetch: () => void;
|
|
39
43
|
} | {
|
|
40
44
|
data: Ref<DataOf<T>>;
|
|
41
45
|
loading: Ref<false>;
|
|
42
46
|
error: Ref<undefined>;
|
|
47
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
43
48
|
refetch: () => void;
|
|
44
49
|
} | {
|
|
45
50
|
data: Ref<DataOf<T>>;
|
|
46
51
|
loading: Ref<false>;
|
|
47
52
|
error: Ref<AggregatedError>;
|
|
53
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
48
54
|
refetch: () => void;
|
|
49
55
|
};
|
|
50
56
|
type UseQueryFn = {
|
|
@@ -60,14 +66,17 @@ type Subscription<T extends Artifact<'subscription'>> = {
|
|
|
60
66
|
data: Ref<undefined>;
|
|
61
67
|
loading: Ref<true>;
|
|
62
68
|
error: Ref<undefined>;
|
|
69
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
63
70
|
} | {
|
|
64
71
|
data: Ref<DataOf<T> | undefined>;
|
|
65
72
|
loading: Ref<false>;
|
|
66
73
|
error: Ref<undefined>;
|
|
74
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
67
75
|
} | {
|
|
68
76
|
data: Ref<DataOf<T> | undefined>;
|
|
69
77
|
loading: Ref<false>;
|
|
70
78
|
error: Ref<AggregatedError>;
|
|
79
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
71
80
|
};
|
|
72
81
|
type UseSubscriptionOptions<T extends Artifact<'subscription'>> = SubscriptionOptions & {
|
|
73
82
|
skip?: boolean;
|
|
@@ -81,14 +90,17 @@ type MutationResult<T extends Artifact<'mutation'>> = {
|
|
|
81
90
|
data: Ref<undefined>;
|
|
82
91
|
loading: Ref<true>;
|
|
83
92
|
error: Ref<undefined>;
|
|
93
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
84
94
|
} | {
|
|
85
95
|
data: Ref<DataOf<T> | undefined>;
|
|
86
96
|
loading: Ref<false>;
|
|
87
97
|
error: Ref<undefined>;
|
|
98
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
88
99
|
} | {
|
|
89
100
|
data: Ref<DataOf<T> | undefined>;
|
|
90
101
|
loading: Ref<false>;
|
|
91
102
|
error: Ref<AggregatedError>;
|
|
103
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
92
104
|
};
|
|
93
105
|
type UseMutationOptions = MutationOptions;
|
|
94
106
|
type Mutation<T extends Artifact<'mutation'>> = [(...[variables, options]: VariablesOf<T> extends Record<string, never> ? [undefined?, UseMutationOptions?] : [VariablesOf<T>, UseMutationOptions?]) => Promise<DataOf<T>>, MutationResult<T>];
|
|
@@ -98,12 +110,15 @@ declare const useMutation: <T extends Artifact<"mutation">>(mutation: T) => Muta
|
|
|
98
110
|
type UseFragmentOptions = FragmentOptions;
|
|
99
111
|
type Fragment<T extends Artifact<'fragment'>> = {
|
|
100
112
|
data: DataOf<T>;
|
|
113
|
+
metadata: OperationResult['metadata'];
|
|
101
114
|
};
|
|
102
115
|
type FragmentList<T extends Artifact<'fragment'>> = {
|
|
103
116
|
data: DataOf<T>[];
|
|
117
|
+
metadata: OperationResult['metadata'];
|
|
104
118
|
};
|
|
105
119
|
type OptionalFragment<T extends Artifact<'fragment'>> = {
|
|
106
120
|
data: DataOf<T> | null;
|
|
121
|
+
metadata: OperationResult['metadata'];
|
|
107
122
|
};
|
|
108
123
|
type UseFragmentFn = {
|
|
109
124
|
<T extends Artifact<'fragment'>>(fragment: T, fragmentRef: MaybeRefOrGetter<FragmentRefs<T['name']>[]>, ...options: [MaybeRefOrGetter<UseFragmentOptions>?]): FragmentList<T>;
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AggregatedError, Artifact, Client, DataOf, FragmentOptions, FragmentRefs, MutationOptions, QueryOptions, SchemaMeta, SubscriptionOptions, VariablesOf } from "@mearie/core";
|
|
1
|
+
import { AggregatedError, Artifact, Client, DataOf, FragmentOptions, FragmentRefs, MutationOptions, OperationResult, QueryOptions, SchemaMeta, SubscriptionOptions, VariablesOf } from "@mearie/core";
|
|
2
2
|
import { App, MaybeRefOrGetter, Ref } from "vue";
|
|
3
3
|
export * from "@mearie/core";
|
|
4
4
|
|
|
@@ -19,32 +19,38 @@ type Query<T extends Artifact<'query'>> = {
|
|
|
19
19
|
data: Ref<undefined>;
|
|
20
20
|
loading: Ref<true>;
|
|
21
21
|
error: Ref<undefined>;
|
|
22
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
22
23
|
refetch: () => void;
|
|
23
24
|
} | {
|
|
24
25
|
data: Ref<DataOf<T>>;
|
|
25
26
|
loading: Ref<false>;
|
|
26
27
|
error: Ref<undefined>;
|
|
28
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
27
29
|
refetch: () => void;
|
|
28
30
|
} | {
|
|
29
31
|
data: Ref<DataOf<T> | undefined>;
|
|
30
32
|
loading: Ref<false>;
|
|
31
33
|
error: Ref<AggregatedError>;
|
|
34
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
32
35
|
refetch: () => void;
|
|
33
36
|
};
|
|
34
37
|
type DefinedQuery<T extends Artifact<'query'>> = {
|
|
35
38
|
data: Ref<DataOf<T>>;
|
|
36
39
|
loading: Ref<true>;
|
|
37
40
|
error: Ref<undefined>;
|
|
41
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
38
42
|
refetch: () => void;
|
|
39
43
|
} | {
|
|
40
44
|
data: Ref<DataOf<T>>;
|
|
41
45
|
loading: Ref<false>;
|
|
42
46
|
error: Ref<undefined>;
|
|
47
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
43
48
|
refetch: () => void;
|
|
44
49
|
} | {
|
|
45
50
|
data: Ref<DataOf<T>>;
|
|
46
51
|
loading: Ref<false>;
|
|
47
52
|
error: Ref<AggregatedError>;
|
|
53
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
48
54
|
refetch: () => void;
|
|
49
55
|
};
|
|
50
56
|
type UseQueryFn = {
|
|
@@ -60,14 +66,17 @@ type Subscription<T extends Artifact<'subscription'>> = {
|
|
|
60
66
|
data: Ref<undefined>;
|
|
61
67
|
loading: Ref<true>;
|
|
62
68
|
error: Ref<undefined>;
|
|
69
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
63
70
|
} | {
|
|
64
71
|
data: Ref<DataOf<T> | undefined>;
|
|
65
72
|
loading: Ref<false>;
|
|
66
73
|
error: Ref<undefined>;
|
|
74
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
67
75
|
} | {
|
|
68
76
|
data: Ref<DataOf<T> | undefined>;
|
|
69
77
|
loading: Ref<false>;
|
|
70
78
|
error: Ref<AggregatedError>;
|
|
79
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
71
80
|
};
|
|
72
81
|
type UseSubscriptionOptions<T extends Artifact<'subscription'>> = SubscriptionOptions & {
|
|
73
82
|
skip?: boolean;
|
|
@@ -81,14 +90,17 @@ type MutationResult<T extends Artifact<'mutation'>> = {
|
|
|
81
90
|
data: Ref<undefined>;
|
|
82
91
|
loading: Ref<true>;
|
|
83
92
|
error: Ref<undefined>;
|
|
93
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
84
94
|
} | {
|
|
85
95
|
data: Ref<DataOf<T> | undefined>;
|
|
86
96
|
loading: Ref<false>;
|
|
87
97
|
error: Ref<undefined>;
|
|
98
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
88
99
|
} | {
|
|
89
100
|
data: Ref<DataOf<T> | undefined>;
|
|
90
101
|
loading: Ref<false>;
|
|
91
102
|
error: Ref<AggregatedError>;
|
|
103
|
+
metadata: Ref<OperationResult['metadata']>;
|
|
92
104
|
};
|
|
93
105
|
type UseMutationOptions = MutationOptions;
|
|
94
106
|
type Mutation<T extends Artifact<'mutation'>> = [(...[variables, options]: VariablesOf<T> extends Record<string, never> ? [undefined?, UseMutationOptions?] : [VariablesOf<T>, UseMutationOptions?]) => Promise<DataOf<T>>, MutationResult<T>];
|
|
@@ -98,12 +110,15 @@ declare const useMutation: <T extends Artifact<"mutation">>(mutation: T) => Muta
|
|
|
98
110
|
type UseFragmentOptions = FragmentOptions;
|
|
99
111
|
type Fragment<T extends Artifact<'fragment'>> = {
|
|
100
112
|
data: DataOf<T>;
|
|
113
|
+
metadata: OperationResult['metadata'];
|
|
101
114
|
};
|
|
102
115
|
type FragmentList<T extends Artifact<'fragment'>> = {
|
|
103
116
|
data: DataOf<T>[];
|
|
117
|
+
metadata: OperationResult['metadata'];
|
|
104
118
|
};
|
|
105
119
|
type OptionalFragment<T extends Artifact<'fragment'>> = {
|
|
106
120
|
data: DataOf<T> | null;
|
|
121
|
+
metadata: OperationResult['metadata'];
|
|
107
122
|
};
|
|
108
123
|
type UseFragmentFn = {
|
|
109
124
|
<T extends Artifact<'fragment'>>(fragment: T, fragmentRef: MaybeRefOrGetter<FragmentRefs<T['name']>[]>, ...options: [MaybeRefOrGetter<UseFragmentOptions>?]): FragmentList<T>;
|
package/dist/index.mjs
CHANGED
|
@@ -23,6 +23,7 @@ const useQuery = ((query, variables, options) => {
|
|
|
23
23
|
const data = ref(initialOpts?.initialData);
|
|
24
24
|
const loading = ref(!initialOpts?.skip && !initialOpts?.initialData);
|
|
25
25
|
const error = ref(void 0);
|
|
26
|
+
const metadata = ref();
|
|
26
27
|
let unsubscribe = null;
|
|
27
28
|
let initialized = false;
|
|
28
29
|
const execute = () => {
|
|
@@ -32,6 +33,7 @@ const useQuery = ((query, variables, options) => {
|
|
|
32
33
|
initialized = true;
|
|
33
34
|
error.value = void 0;
|
|
34
35
|
unsubscribe = pipe(client.executeQuery(query, toValue(variables), toValue(options)), subscribe({ next: (result) => {
|
|
36
|
+
metadata.value = result.metadata;
|
|
35
37
|
if (result.errors && result.errors.length > 0) {
|
|
36
38
|
error.value = new AggregatedError(result.errors);
|
|
37
39
|
loading.value = false;
|
|
@@ -52,6 +54,7 @@ const useQuery = ((query, variables, options) => {
|
|
|
52
54
|
data,
|
|
53
55
|
loading,
|
|
54
56
|
error,
|
|
57
|
+
metadata,
|
|
55
58
|
refetch: execute
|
|
56
59
|
};
|
|
57
60
|
});
|
|
@@ -63,6 +66,7 @@ const useSubscription = (subscription, ...[variables, options]) => {
|
|
|
63
66
|
const data = ref(void 0);
|
|
64
67
|
const loading = ref(!toValue(options)?.skip);
|
|
65
68
|
const error = ref(void 0);
|
|
69
|
+
const metadata = ref();
|
|
66
70
|
let unsubscribe = null;
|
|
67
71
|
const execute = () => {
|
|
68
72
|
unsubscribe?.();
|
|
@@ -70,6 +74,7 @@ const useSubscription = (subscription, ...[variables, options]) => {
|
|
|
70
74
|
loading.value = true;
|
|
71
75
|
error.value = void 0;
|
|
72
76
|
unsubscribe = pipe(client.executeSubscription(subscription, toValue(variables), toValue(options)), subscribe({ next: (result) => {
|
|
77
|
+
metadata.value = result.metadata;
|
|
73
78
|
if (result.errors && result.errors.length > 0) {
|
|
74
79
|
const err = new AggregatedError(result.errors);
|
|
75
80
|
error.value = err;
|
|
@@ -92,7 +97,8 @@ const useSubscription = (subscription, ...[variables, options]) => {
|
|
|
92
97
|
return {
|
|
93
98
|
data,
|
|
94
99
|
loading,
|
|
95
|
-
error
|
|
100
|
+
error,
|
|
101
|
+
metadata
|
|
96
102
|
};
|
|
97
103
|
};
|
|
98
104
|
|
|
@@ -103,17 +109,21 @@ const useMutation = (mutation) => {
|
|
|
103
109
|
const data = ref(void 0);
|
|
104
110
|
const loading = ref(false);
|
|
105
111
|
const error = ref(void 0);
|
|
112
|
+
const metadata = ref();
|
|
106
113
|
const execute = async (variables, options) => {
|
|
107
114
|
loading.value = true;
|
|
108
115
|
error.value = void 0;
|
|
116
|
+
metadata.value = void 0;
|
|
109
117
|
try {
|
|
110
118
|
const result = await pipe(client.executeMutation(mutation, variables, options), take(1), collect);
|
|
111
119
|
if (result.errors && result.errors.length > 0) {
|
|
112
120
|
const err = new AggregatedError(result.errors);
|
|
121
|
+
metadata.value = result.metadata;
|
|
113
122
|
error.value = err;
|
|
114
123
|
loading.value = false;
|
|
115
124
|
throw err;
|
|
116
125
|
}
|
|
126
|
+
metadata.value = result.metadata;
|
|
117
127
|
data.value = result.data;
|
|
118
128
|
loading.value = false;
|
|
119
129
|
return result.data;
|
|
@@ -126,7 +136,8 @@ const useMutation = (mutation) => {
|
|
|
126
136
|
return [execute, {
|
|
127
137
|
data,
|
|
128
138
|
loading,
|
|
129
|
-
error
|
|
139
|
+
error,
|
|
140
|
+
metadata
|
|
130
141
|
}];
|
|
131
142
|
};
|
|
132
143
|
|
|
@@ -136,27 +147,37 @@ const useFragment = ((fragment, fragmentRef, ...[options]) => {
|
|
|
136
147
|
const client = useClient();
|
|
137
148
|
const initialRef = toValue(fragmentRef);
|
|
138
149
|
let initialData;
|
|
150
|
+
let initialMetadata;
|
|
139
151
|
if (initialRef == null) initialData = null;
|
|
140
152
|
else {
|
|
141
153
|
const result = pipe(client.executeFragment(fragment, initialRef, toValue(options)), peek);
|
|
142
154
|
if (result.data === void 0) throw new Error("Fragment data not found");
|
|
143
155
|
initialData = result.data;
|
|
156
|
+
initialMetadata = result.metadata;
|
|
144
157
|
}
|
|
145
158
|
const data = ref(initialData);
|
|
159
|
+
const metadata = ref(initialMetadata);
|
|
146
160
|
watchEffect((onCleanup) => {
|
|
147
161
|
const currentRef = toValue(fragmentRef);
|
|
148
162
|
if (currentRef == null) {
|
|
149
163
|
data.value = null;
|
|
164
|
+
metadata.value = void 0;
|
|
150
165
|
return;
|
|
151
166
|
}
|
|
152
167
|
const unsubscribe = pipe(client.executeFragment(fragment, currentRef, toValue(options)), subscribe({ next: (result) => {
|
|
168
|
+
metadata.value = result.metadata;
|
|
153
169
|
if (result.data !== void 0) data.value = result.data;
|
|
154
170
|
} }));
|
|
155
171
|
onCleanup(() => unsubscribe());
|
|
156
172
|
});
|
|
157
|
-
return {
|
|
158
|
-
|
|
159
|
-
|
|
173
|
+
return {
|
|
174
|
+
get data() {
|
|
175
|
+
return data.value;
|
|
176
|
+
},
|
|
177
|
+
get metadata() {
|
|
178
|
+
return metadata.value;
|
|
179
|
+
}
|
|
180
|
+
};
|
|
160
181
|
});
|
|
161
182
|
|
|
162
183
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mearie/vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Type-safe, zero-overhead GraphQL client",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"graphql",
|
|
7
7
|
"graphql-client",
|
|
8
8
|
"typescript",
|
|
9
|
+
"type-safe",
|
|
9
10
|
"codegen",
|
|
10
|
-
"cache"
|
|
11
|
+
"cache",
|
|
12
|
+
"normalized-cache",
|
|
13
|
+
"react",
|
|
14
|
+
"vue",
|
|
15
|
+
"svelte",
|
|
16
|
+
"solid",
|
|
17
|
+
"vite"
|
|
11
18
|
],
|
|
12
|
-
"homepage": "https://
|
|
19
|
+
"homepage": "https://mearie.dev/",
|
|
13
20
|
"bugs": {
|
|
14
21
|
"url": "https://github.com/devunt/mearie/issues"
|
|
15
22
|
},
|
|
@@ -45,7 +52,7 @@
|
|
|
45
52
|
"README.md"
|
|
46
53
|
],
|
|
47
54
|
"dependencies": {
|
|
48
|
-
"@mearie/core": "0.
|
|
55
|
+
"@mearie/core": "0.3.0"
|
|
49
56
|
},
|
|
50
57
|
"devDependencies": {
|
|
51
58
|
"tsdown": "^0.20.3",
|