@mearie/solid 0.0.1-next.1 → 0.0.1-next.4
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/README.md +21 -10
- package/dist/index.cjs +114 -20
- package/dist/index.d.cts +32 -25
- package/dist/index.d.ts +32 -25
- package/dist/index.js +108 -20
- package/package.json +43 -14
package/README.md
CHANGED
|
@@ -2,33 +2,44 @@
|
|
|
2
2
|
|
|
3
3
|
Solid bindings for Mearie GraphQL client.
|
|
4
4
|
|
|
5
|
-
This package provides Solid primitives
|
|
6
|
-
applications.
|
|
5
|
+
This package provides Solid primitives, components, and the GraphQL client
|
|
6
|
+
runtime for using Mearie in Solid applications.
|
|
7
7
|
|
|
8
8
|
## Installation
|
|
9
9
|
|
|
10
10
|
```bash
|
|
11
|
-
npm install
|
|
11
|
+
npm install -D mearie
|
|
12
|
+
npm install @mearie/solid
|
|
12
13
|
```
|
|
13
14
|
|
|
15
|
+
The `mearie` package provides build-time code generation, while `@mearie/solid`
|
|
16
|
+
includes the runtime client and Solid-specific primitives.
|
|
17
|
+
|
|
14
18
|
## Usage
|
|
15
19
|
|
|
20
|
+
First, create a client and wrap your app with the provider:
|
|
21
|
+
|
|
16
22
|
```tsx
|
|
23
|
+
// src/App.tsx
|
|
17
24
|
import { type Component } from 'solid-js';
|
|
18
|
-
import { createClient, httpLink, cacheLink,
|
|
19
|
-
import { ClientProvider, createQuery } from '@mearie/solid';
|
|
25
|
+
import { createClient, httpLink, cacheLink, ClientProvider } from '@mearie/solid';
|
|
20
26
|
|
|
21
27
|
const client = createClient({
|
|
22
28
|
links: [cacheLink(), httpLink({ url: 'https://api.example.com/graphql' })],
|
|
23
29
|
});
|
|
24
30
|
|
|
25
31
|
const App: Component = () => {
|
|
26
|
-
return
|
|
27
|
-
<ClientProvider client={client}>
|
|
28
|
-
<UserProfile userId="1" />
|
|
29
|
-
</ClientProvider>
|
|
30
|
-
);
|
|
32
|
+
return <ClientProvider client={client}>{/* Your app components */}</ClientProvider>;
|
|
31
33
|
};
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Then use it in your components:
|
|
37
|
+
|
|
38
|
+
```tsx
|
|
39
|
+
// src/components/UserProfile.tsx
|
|
40
|
+
import { type Component } from 'solid-js';
|
|
41
|
+
import { graphql } from '$mearie';
|
|
42
|
+
import { createQuery } from '@mearie/solid';
|
|
32
43
|
|
|
33
44
|
interface UserProfileProps {
|
|
34
45
|
userId: string;
|
package/dist/index.cjs
CHANGED
|
@@ -21,8 +21,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
}) : target, mod));
|
|
22
22
|
|
|
23
23
|
//#endregion
|
|
24
|
+
let __mearie_core = require("@mearie/core");
|
|
25
|
+
__mearie_core = __toESM(__mearie_core);
|
|
24
26
|
let solid_js = require("solid-js");
|
|
25
27
|
solid_js = __toESM(solid_js);
|
|
28
|
+
let __mearie_core_stream = require("@mearie/core/stream");
|
|
29
|
+
__mearie_core_stream = __toESM(__mearie_core_stream);
|
|
26
30
|
|
|
27
31
|
//#region src/client-provider.tsx
|
|
28
32
|
const ClientContext = (0, solid_js.createContext)();
|
|
@@ -37,10 +41,37 @@ const useClient = () => {
|
|
|
37
41
|
|
|
38
42
|
//#endregion
|
|
39
43
|
//#region src/create-query.ts
|
|
40
|
-
const createQuery = (
|
|
41
|
-
const
|
|
42
|
-
const [
|
|
43
|
-
const [
|
|
44
|
+
const createQuery = (query, ...[variables, options]) => {
|
|
45
|
+
const client = useClient();
|
|
46
|
+
const [data, setData] = (0, solid_js.createSignal)();
|
|
47
|
+
const [loading, setLoading] = (0, solid_js.createSignal)(!options?.()?.skip);
|
|
48
|
+
const [error, setError] = (0, solid_js.createSignal)();
|
|
49
|
+
let unsubscribe = null;
|
|
50
|
+
const execute = () => {
|
|
51
|
+
unsubscribe?.();
|
|
52
|
+
if (options?.()?.skip) return;
|
|
53
|
+
setLoading(true);
|
|
54
|
+
setError(void 0);
|
|
55
|
+
unsubscribe = (0, __mearie_core_stream.pipe)(client.executeQuery(query, typeof variables === "function" ? variables() : variables, options?.()), (0, __mearie_core_stream.subscribe)({ next: (result) => {
|
|
56
|
+
if (result.errors && result.errors.length > 0) {
|
|
57
|
+
setError(new __mearie_core.AggregatedError(result.errors));
|
|
58
|
+
setLoading(false);
|
|
59
|
+
} else {
|
|
60
|
+
setData(() => result.data);
|
|
61
|
+
setLoading(false);
|
|
62
|
+
setError(void 0);
|
|
63
|
+
}
|
|
64
|
+
} }));
|
|
65
|
+
};
|
|
66
|
+
const refetch = () => {
|
|
67
|
+
(0, solid_js.untrack)(execute);
|
|
68
|
+
};
|
|
69
|
+
(0, solid_js.createEffect)(() => {
|
|
70
|
+
execute();
|
|
71
|
+
(0, solid_js.onCleanup)(() => {
|
|
72
|
+
unsubscribe?.();
|
|
73
|
+
});
|
|
74
|
+
});
|
|
44
75
|
return {
|
|
45
76
|
get data() {
|
|
46
77
|
return data();
|
|
@@ -51,16 +82,39 @@ const createQuery = (document, variables) => {
|
|
|
51
82
|
get error() {
|
|
52
83
|
return error();
|
|
53
84
|
},
|
|
54
|
-
refetch
|
|
85
|
+
refetch
|
|
55
86
|
};
|
|
56
87
|
};
|
|
57
88
|
|
|
58
89
|
//#endregion
|
|
59
90
|
//#region src/create-subscription.ts
|
|
60
|
-
const createSubscription = (
|
|
61
|
-
const
|
|
62
|
-
const [
|
|
63
|
-
const [
|
|
91
|
+
const createSubscription = (subscription, ...[variables, options]) => {
|
|
92
|
+
const client = useClient();
|
|
93
|
+
const [data, setData] = (0, solid_js.createSignal)();
|
|
94
|
+
const [loading, setLoading] = (0, solid_js.createSignal)(!options?.()?.skip);
|
|
95
|
+
const [error, setError] = (0, solid_js.createSignal)();
|
|
96
|
+
(0, solid_js.createEffect)(() => {
|
|
97
|
+
if (options?.()?.skip) return;
|
|
98
|
+
setLoading(true);
|
|
99
|
+
setError(void 0);
|
|
100
|
+
const unsubscribe = (0, __mearie_core_stream.pipe)(client.executeSubscription(subscription, typeof variables === "function" ? variables() : variables, options?.()), (0, __mearie_core_stream.subscribe)({ next: (result) => {
|
|
101
|
+
if (result.errors && result.errors.length > 0) {
|
|
102
|
+
const err = new __mearie_core.AggregatedError(result.errors);
|
|
103
|
+
setError(err);
|
|
104
|
+
setLoading(false);
|
|
105
|
+
options?.()?.onError?.(err);
|
|
106
|
+
} else {
|
|
107
|
+
const resultData = result.data;
|
|
108
|
+
setData(() => resultData);
|
|
109
|
+
setLoading(false);
|
|
110
|
+
setError(void 0);
|
|
111
|
+
options?.()?.onData?.(resultData);
|
|
112
|
+
}
|
|
113
|
+
} }));
|
|
114
|
+
(0, solid_js.onCleanup)(() => {
|
|
115
|
+
unsubscribe();
|
|
116
|
+
});
|
|
117
|
+
});
|
|
64
118
|
return {
|
|
65
119
|
get data() {
|
|
66
120
|
return data();
|
|
@@ -76,11 +130,32 @@ const createSubscription = (document, variables, options) => {
|
|
|
76
130
|
|
|
77
131
|
//#endregion
|
|
78
132
|
//#region src/create-mutation.ts
|
|
79
|
-
const createMutation = (
|
|
80
|
-
const
|
|
81
|
-
const [
|
|
82
|
-
const [
|
|
83
|
-
|
|
133
|
+
const createMutation = (mutation) => {
|
|
134
|
+
const client = useClient();
|
|
135
|
+
const [data, setData] = (0, solid_js.createSignal)();
|
|
136
|
+
const [loading, setLoading] = (0, solid_js.createSignal)(false);
|
|
137
|
+
const [error, setError] = (0, solid_js.createSignal)();
|
|
138
|
+
const execute = async (variables, options) => {
|
|
139
|
+
setLoading(true);
|
|
140
|
+
setError(void 0);
|
|
141
|
+
try {
|
|
142
|
+
const result = await (0, __mearie_core_stream.pipe)(client.executeMutation(mutation, variables, options), __mearie_core_stream.collect);
|
|
143
|
+
if (result.errors && result.errors.length > 0) {
|
|
144
|
+
const err = new __mearie_core.AggregatedError(result.errors);
|
|
145
|
+
setError(err);
|
|
146
|
+
setLoading(false);
|
|
147
|
+
throw err;
|
|
148
|
+
}
|
|
149
|
+
setData(() => result.data);
|
|
150
|
+
setLoading(false);
|
|
151
|
+
return result.data;
|
|
152
|
+
} catch (err) {
|
|
153
|
+
if (err instanceof __mearie_core.AggregatedError) setError(err);
|
|
154
|
+
setLoading(false);
|
|
155
|
+
throw err;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
return [execute, {
|
|
84
159
|
get data() {
|
|
85
160
|
return data();
|
|
86
161
|
},
|
|
@@ -89,15 +164,28 @@ const createMutation = (document) => {
|
|
|
89
164
|
},
|
|
90
165
|
get error() {
|
|
91
166
|
return error();
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
};
|
|
167
|
+
}
|
|
168
|
+
}];
|
|
95
169
|
};
|
|
96
170
|
|
|
97
171
|
//#endregion
|
|
98
172
|
//#region src/create-fragment.ts
|
|
99
|
-
const createFragment = (
|
|
100
|
-
|
|
173
|
+
const createFragment = (fragment, fragmentRef, options) => {
|
|
174
|
+
const client = useClient();
|
|
175
|
+
const result = (0, __mearie_core_stream.pipe)(client.executeFragment(fragment, fragmentRef(), options?.()), __mearie_core_stream.peek);
|
|
176
|
+
if (result.data === void 0) throw new Error("Fragment data not found");
|
|
177
|
+
const [data, setData] = (0, solid_js.createSignal)(result.data);
|
|
178
|
+
(0, solid_js.createEffect)(() => {
|
|
179
|
+
const unsubscribe = (0, __mearie_core_stream.pipe)(client.executeFragment(fragment, fragmentRef(), options?.()), (0, __mearie_core_stream.subscribe)({ next: (result$1) => {
|
|
180
|
+
if (result$1.data !== void 0) setData(() => result$1.data);
|
|
181
|
+
} }));
|
|
182
|
+
(0, solid_js.onCleanup)(() => {
|
|
183
|
+
unsubscribe();
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
return { get data() {
|
|
187
|
+
return data();
|
|
188
|
+
} };
|
|
101
189
|
};
|
|
102
190
|
|
|
103
191
|
//#endregion
|
|
@@ -106,4 +194,10 @@ exports.createFragment = createFragment;
|
|
|
106
194
|
exports.createMutation = createMutation;
|
|
107
195
|
exports.createQuery = createQuery;
|
|
108
196
|
exports.createSubscription = createSubscription;
|
|
109
|
-
exports.useClient = useClient;
|
|
197
|
+
exports.useClient = useClient;
|
|
198
|
+
Object.keys(__mearie_core).forEach(function (k) {
|
|
199
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
200
|
+
enumerable: true,
|
|
201
|
+
get: function () { return __mearie_core[k]; }
|
|
202
|
+
});
|
|
203
|
+
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { AggregatedError, Artifact, Client, DataOf, FragmentOptions, FragmentRefs, MutationOptions, QueryOptions, SubscriptionOptions, VariablesOf } from "@mearie/core";
|
|
1
2
|
import { Accessor, JSX } from "solid-js";
|
|
2
|
-
|
|
3
|
+
export * from "@mearie/core";
|
|
3
4
|
|
|
4
5
|
//#region src/client-provider.d.ts
|
|
5
6
|
type ClientProviderProps = {
|
|
@@ -10,65 +11,71 @@ declare const ClientProvider: (props: ClientProviderProps) => JSX.Element;
|
|
|
10
11
|
declare const useClient: () => Client;
|
|
11
12
|
//#endregion
|
|
12
13
|
//#region src/create-query.d.ts
|
|
13
|
-
type
|
|
14
|
+
type CreateQueryOptions = QueryOptions & {
|
|
15
|
+
skip?: boolean;
|
|
16
|
+
};
|
|
17
|
+
type Query<T extends Artifact<'query'>> = {
|
|
14
18
|
data: undefined;
|
|
15
19
|
loading: true;
|
|
16
20
|
error: undefined;
|
|
17
21
|
refetch: () => void;
|
|
18
22
|
} | {
|
|
19
|
-
data: DataOf<
|
|
23
|
+
data: DataOf<T>;
|
|
20
24
|
loading: false;
|
|
21
25
|
error: undefined;
|
|
22
26
|
refetch: () => void;
|
|
23
27
|
} | {
|
|
24
|
-
data: DataOf<
|
|
28
|
+
data: DataOf<T> | undefined;
|
|
25
29
|
loading: false;
|
|
26
|
-
error:
|
|
30
|
+
error: AggregatedError;
|
|
27
31
|
refetch: () => void;
|
|
28
32
|
};
|
|
29
|
-
declare const createQuery: <
|
|
33
|
+
declare const createQuery: <T extends Artifact<"query">>(query: T, ...[variables, options]: VariablesOf<T> extends undefined ? [undefined?, Accessor<CreateQueryOptions>?] : [Accessor<VariablesOf<T>>, Accessor<CreateQueryOptions>?]) => Query<T>;
|
|
30
34
|
//#endregion
|
|
31
35
|
//#region src/create-subscription.d.ts
|
|
32
|
-
type
|
|
36
|
+
type Subscription<T extends Artifact<'subscription'>> = {
|
|
33
37
|
data: undefined;
|
|
34
38
|
loading: true;
|
|
35
39
|
error: undefined;
|
|
36
40
|
} | {
|
|
37
|
-
data: DataOf<
|
|
41
|
+
data: DataOf<T> | undefined;
|
|
38
42
|
loading: false;
|
|
39
43
|
error: undefined;
|
|
40
44
|
} | {
|
|
41
|
-
data: DataOf<
|
|
45
|
+
data: DataOf<T> | undefined;
|
|
42
46
|
loading: false;
|
|
43
|
-
error:
|
|
47
|
+
error: AggregatedError;
|
|
44
48
|
};
|
|
45
|
-
type CreateSubscriptionOptions<
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
type CreateSubscriptionOptions<T extends Artifact<'subscription'>> = SubscriptionOptions & {
|
|
50
|
+
skip?: boolean;
|
|
51
|
+
onData?: (data: DataOf<T>) => void;
|
|
52
|
+
onError?: (error: AggregatedError) => void;
|
|
48
53
|
};
|
|
49
|
-
declare const createSubscription: <
|
|
54
|
+
declare const createSubscription: <T extends Artifact<"subscription">>(subscription: T, ...[variables, options]: VariablesOf<T> extends undefined ? [undefined?, Accessor<CreateSubscriptionOptions<T>>?] : [Accessor<VariablesOf<T>>, Accessor<CreateSubscriptionOptions<T>>?]) => Subscription<T>;
|
|
50
55
|
//#endregion
|
|
51
56
|
//#region src/create-mutation.d.ts
|
|
52
|
-
type
|
|
57
|
+
type MutationResult<T extends Artifact<'mutation'>> = {
|
|
53
58
|
data: undefined;
|
|
54
59
|
loading: true;
|
|
55
60
|
error: undefined;
|
|
56
|
-
mutate: (variables: VariablesOf<Document$1>) => Promise<DataOf<Document$1>>;
|
|
57
61
|
} | {
|
|
58
|
-
data: DataOf<
|
|
62
|
+
data: DataOf<T> | undefined;
|
|
59
63
|
loading: false;
|
|
60
64
|
error: undefined;
|
|
61
|
-
mutate: (variables: VariablesOf<Document$1>) => Promise<DataOf<Document$1>>;
|
|
62
65
|
} | {
|
|
63
|
-
data: DataOf<
|
|
66
|
+
data: DataOf<T> | undefined;
|
|
64
67
|
loading: false;
|
|
65
|
-
error:
|
|
66
|
-
mutate: (variables: VariablesOf<Document$1>) => Promise<DataOf<Document$1>>;
|
|
68
|
+
error: AggregatedError;
|
|
67
69
|
};
|
|
68
|
-
|
|
70
|
+
type CreateMutationOptions = MutationOptions;
|
|
71
|
+
type Mutation<T extends Artifact<'mutation'>> = [(...[variables, options]: VariablesOf<T> extends undefined ? [undefined?, CreateMutationOptions?] : [VariablesOf<T>, CreateMutationOptions?]) => Promise<DataOf<T>>, MutationResult<T>];
|
|
72
|
+
declare const createMutation: <T extends Artifact<"mutation">>(mutation: T) => Mutation<T>;
|
|
69
73
|
//#endregion
|
|
70
74
|
//#region src/create-fragment.d.ts
|
|
71
|
-
type
|
|
72
|
-
|
|
75
|
+
type CreateFragmentOptions = FragmentOptions;
|
|
76
|
+
type Fragment<T extends Artifact<'fragment'>> = {
|
|
77
|
+
data: DataOf<T>;
|
|
78
|
+
};
|
|
79
|
+
declare const createFragment: <T extends Artifact<"fragment">>(fragment: T, fragmentRef: Accessor<FragmentRefs<T["name"]>>, options?: Accessor<CreateFragmentOptions>) => Fragment<T>;
|
|
73
80
|
//#endregion
|
|
74
|
-
export { ClientProvider, type ClientProviderProps, type
|
|
81
|
+
export { ClientProvider, type ClientProviderProps, type CreateFragmentOptions, type CreateMutationOptions, type CreateQueryOptions, type CreateSubscriptionOptions, type Fragment, type Mutation, type MutationResult, type Query, type Subscription, createFragment, createMutation, createQuery, createSubscription, useClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { AggregatedError, Artifact, Client, DataOf, FragmentOptions, FragmentRefs, MutationOptions, QueryOptions, SubscriptionOptions, VariablesOf } from "@mearie/core";
|
|
1
2
|
import { Accessor, JSX } from "solid-js";
|
|
2
|
-
|
|
3
|
+
export * from "@mearie/core";
|
|
3
4
|
|
|
4
5
|
//#region src/client-provider.d.ts
|
|
5
6
|
type ClientProviderProps = {
|
|
@@ -10,65 +11,71 @@ declare const ClientProvider: (props: ClientProviderProps) => JSX.Element;
|
|
|
10
11
|
declare const useClient: () => Client;
|
|
11
12
|
//#endregion
|
|
12
13
|
//#region src/create-query.d.ts
|
|
13
|
-
type
|
|
14
|
+
type CreateQueryOptions = QueryOptions & {
|
|
15
|
+
skip?: boolean;
|
|
16
|
+
};
|
|
17
|
+
type Query<T extends Artifact<'query'>> = {
|
|
14
18
|
data: undefined;
|
|
15
19
|
loading: true;
|
|
16
20
|
error: undefined;
|
|
17
21
|
refetch: () => void;
|
|
18
22
|
} | {
|
|
19
|
-
data: DataOf<
|
|
23
|
+
data: DataOf<T>;
|
|
20
24
|
loading: false;
|
|
21
25
|
error: undefined;
|
|
22
26
|
refetch: () => void;
|
|
23
27
|
} | {
|
|
24
|
-
data: DataOf<
|
|
28
|
+
data: DataOf<T> | undefined;
|
|
25
29
|
loading: false;
|
|
26
|
-
error:
|
|
30
|
+
error: AggregatedError;
|
|
27
31
|
refetch: () => void;
|
|
28
32
|
};
|
|
29
|
-
declare const createQuery: <
|
|
33
|
+
declare const createQuery: <T extends Artifact<"query">>(query: T, ...[variables, options]: VariablesOf<T> extends undefined ? [undefined?, Accessor<CreateQueryOptions>?] : [Accessor<VariablesOf<T>>, Accessor<CreateQueryOptions>?]) => Query<T>;
|
|
30
34
|
//#endregion
|
|
31
35
|
//#region src/create-subscription.d.ts
|
|
32
|
-
type
|
|
36
|
+
type Subscription<T extends Artifact<'subscription'>> = {
|
|
33
37
|
data: undefined;
|
|
34
38
|
loading: true;
|
|
35
39
|
error: undefined;
|
|
36
40
|
} | {
|
|
37
|
-
data: DataOf<
|
|
41
|
+
data: DataOf<T> | undefined;
|
|
38
42
|
loading: false;
|
|
39
43
|
error: undefined;
|
|
40
44
|
} | {
|
|
41
|
-
data: DataOf<
|
|
45
|
+
data: DataOf<T> | undefined;
|
|
42
46
|
loading: false;
|
|
43
|
-
error:
|
|
47
|
+
error: AggregatedError;
|
|
44
48
|
};
|
|
45
|
-
type CreateSubscriptionOptions<
|
|
46
|
-
|
|
47
|
-
|
|
49
|
+
type CreateSubscriptionOptions<T extends Artifact<'subscription'>> = SubscriptionOptions & {
|
|
50
|
+
skip?: boolean;
|
|
51
|
+
onData?: (data: DataOf<T>) => void;
|
|
52
|
+
onError?: (error: AggregatedError) => void;
|
|
48
53
|
};
|
|
49
|
-
declare const createSubscription: <
|
|
54
|
+
declare const createSubscription: <T extends Artifact<"subscription">>(subscription: T, ...[variables, options]: VariablesOf<T> extends undefined ? [undefined?, Accessor<CreateSubscriptionOptions<T>>?] : [Accessor<VariablesOf<T>>, Accessor<CreateSubscriptionOptions<T>>?]) => Subscription<T>;
|
|
50
55
|
//#endregion
|
|
51
56
|
//#region src/create-mutation.d.ts
|
|
52
|
-
type
|
|
57
|
+
type MutationResult<T extends Artifact<'mutation'>> = {
|
|
53
58
|
data: undefined;
|
|
54
59
|
loading: true;
|
|
55
60
|
error: undefined;
|
|
56
|
-
mutate: (variables: VariablesOf<Document$1>) => Promise<DataOf<Document$1>>;
|
|
57
61
|
} | {
|
|
58
|
-
data: DataOf<
|
|
62
|
+
data: DataOf<T> | undefined;
|
|
59
63
|
loading: false;
|
|
60
64
|
error: undefined;
|
|
61
|
-
mutate: (variables: VariablesOf<Document$1>) => Promise<DataOf<Document$1>>;
|
|
62
65
|
} | {
|
|
63
|
-
data: DataOf<
|
|
66
|
+
data: DataOf<T> | undefined;
|
|
64
67
|
loading: false;
|
|
65
|
-
error:
|
|
66
|
-
mutate: (variables: VariablesOf<Document$1>) => Promise<DataOf<Document$1>>;
|
|
68
|
+
error: AggregatedError;
|
|
67
69
|
};
|
|
68
|
-
|
|
70
|
+
type CreateMutationOptions = MutationOptions;
|
|
71
|
+
type Mutation<T extends Artifact<'mutation'>> = [(...[variables, options]: VariablesOf<T> extends undefined ? [undefined?, CreateMutationOptions?] : [VariablesOf<T>, CreateMutationOptions?]) => Promise<DataOf<T>>, MutationResult<T>];
|
|
72
|
+
declare const createMutation: <T extends Artifact<"mutation">>(mutation: T) => Mutation<T>;
|
|
69
73
|
//#endregion
|
|
70
74
|
//#region src/create-fragment.d.ts
|
|
71
|
-
type
|
|
72
|
-
|
|
75
|
+
type CreateFragmentOptions = FragmentOptions;
|
|
76
|
+
type Fragment<T extends Artifact<'fragment'>> = {
|
|
77
|
+
data: DataOf<T>;
|
|
78
|
+
};
|
|
79
|
+
declare const createFragment: <T extends Artifact<"fragment">>(fragment: T, fragmentRef: Accessor<FragmentRefs<T["name"]>>, options?: Accessor<CreateFragmentOptions>) => Fragment<T>;
|
|
73
80
|
//#endregion
|
|
74
|
-
export { ClientProvider, type ClientProviderProps, type
|
|
81
|
+
export { ClientProvider, type ClientProviderProps, type CreateFragmentOptions, type CreateMutationOptions, type CreateQueryOptions, type CreateSubscriptionOptions, type Fragment, type Mutation, type MutationResult, type Query, type Subscription, createFragment, createMutation, createQuery, createSubscription, useClient };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AggregatedError } from "@mearie/core";
|
|
2
|
+
import { createContext, createEffect, createSignal, onCleanup, untrack, useContext } from "solid-js";
|
|
3
|
+
import { collect, peek, pipe, subscribe } from "@mearie/core/stream";
|
|
4
|
+
|
|
5
|
+
export * from "@mearie/core"
|
|
2
6
|
|
|
3
7
|
//#region src/client-provider.tsx
|
|
4
8
|
const ClientContext = createContext();
|
|
@@ -13,10 +17,37 @@ const useClient = () => {
|
|
|
13
17
|
|
|
14
18
|
//#endregion
|
|
15
19
|
//#region src/create-query.ts
|
|
16
|
-
const createQuery = (
|
|
17
|
-
const
|
|
18
|
-
const [
|
|
19
|
-
const [
|
|
20
|
+
const createQuery = (query, ...[variables, options]) => {
|
|
21
|
+
const client = useClient();
|
|
22
|
+
const [data, setData] = createSignal();
|
|
23
|
+
const [loading, setLoading] = createSignal(!options?.()?.skip);
|
|
24
|
+
const [error, setError] = createSignal();
|
|
25
|
+
let unsubscribe = null;
|
|
26
|
+
const execute = () => {
|
|
27
|
+
unsubscribe?.();
|
|
28
|
+
if (options?.()?.skip) return;
|
|
29
|
+
setLoading(true);
|
|
30
|
+
setError(void 0);
|
|
31
|
+
unsubscribe = pipe(client.executeQuery(query, typeof variables === "function" ? variables() : variables, options?.()), subscribe({ next: (result) => {
|
|
32
|
+
if (result.errors && result.errors.length > 0) {
|
|
33
|
+
setError(new AggregatedError(result.errors));
|
|
34
|
+
setLoading(false);
|
|
35
|
+
} else {
|
|
36
|
+
setData(() => result.data);
|
|
37
|
+
setLoading(false);
|
|
38
|
+
setError(void 0);
|
|
39
|
+
}
|
|
40
|
+
} }));
|
|
41
|
+
};
|
|
42
|
+
const refetch = () => {
|
|
43
|
+
untrack(execute);
|
|
44
|
+
};
|
|
45
|
+
createEffect(() => {
|
|
46
|
+
execute();
|
|
47
|
+
onCleanup(() => {
|
|
48
|
+
unsubscribe?.();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
20
51
|
return {
|
|
21
52
|
get data() {
|
|
22
53
|
return data();
|
|
@@ -27,16 +58,39 @@ const createQuery = (document, variables) => {
|
|
|
27
58
|
get error() {
|
|
28
59
|
return error();
|
|
29
60
|
},
|
|
30
|
-
refetch
|
|
61
|
+
refetch
|
|
31
62
|
};
|
|
32
63
|
};
|
|
33
64
|
|
|
34
65
|
//#endregion
|
|
35
66
|
//#region src/create-subscription.ts
|
|
36
|
-
const createSubscription = (
|
|
37
|
-
const
|
|
38
|
-
const [
|
|
39
|
-
const [
|
|
67
|
+
const createSubscription = (subscription, ...[variables, options]) => {
|
|
68
|
+
const client = useClient();
|
|
69
|
+
const [data, setData] = createSignal();
|
|
70
|
+
const [loading, setLoading] = createSignal(!options?.()?.skip);
|
|
71
|
+
const [error, setError] = createSignal();
|
|
72
|
+
createEffect(() => {
|
|
73
|
+
if (options?.()?.skip) return;
|
|
74
|
+
setLoading(true);
|
|
75
|
+
setError(void 0);
|
|
76
|
+
const unsubscribe = pipe(client.executeSubscription(subscription, typeof variables === "function" ? variables() : variables, options?.()), subscribe({ next: (result) => {
|
|
77
|
+
if (result.errors && result.errors.length > 0) {
|
|
78
|
+
const err = new AggregatedError(result.errors);
|
|
79
|
+
setError(err);
|
|
80
|
+
setLoading(false);
|
|
81
|
+
options?.()?.onError?.(err);
|
|
82
|
+
} else {
|
|
83
|
+
const resultData = result.data;
|
|
84
|
+
setData(() => resultData);
|
|
85
|
+
setLoading(false);
|
|
86
|
+
setError(void 0);
|
|
87
|
+
options?.()?.onData?.(resultData);
|
|
88
|
+
}
|
|
89
|
+
} }));
|
|
90
|
+
onCleanup(() => {
|
|
91
|
+
unsubscribe();
|
|
92
|
+
});
|
|
93
|
+
});
|
|
40
94
|
return {
|
|
41
95
|
get data() {
|
|
42
96
|
return data();
|
|
@@ -52,11 +106,32 @@ const createSubscription = (document, variables, options) => {
|
|
|
52
106
|
|
|
53
107
|
//#endregion
|
|
54
108
|
//#region src/create-mutation.ts
|
|
55
|
-
const createMutation = (
|
|
56
|
-
const
|
|
57
|
-
const [
|
|
58
|
-
const [
|
|
59
|
-
|
|
109
|
+
const createMutation = (mutation) => {
|
|
110
|
+
const client = useClient();
|
|
111
|
+
const [data, setData] = createSignal();
|
|
112
|
+
const [loading, setLoading] = createSignal(false);
|
|
113
|
+
const [error, setError] = createSignal();
|
|
114
|
+
const execute = async (variables, options) => {
|
|
115
|
+
setLoading(true);
|
|
116
|
+
setError(void 0);
|
|
117
|
+
try {
|
|
118
|
+
const result = await pipe(client.executeMutation(mutation, variables, options), collect);
|
|
119
|
+
if (result.errors && result.errors.length > 0) {
|
|
120
|
+
const err = new AggregatedError(result.errors);
|
|
121
|
+
setError(err);
|
|
122
|
+
setLoading(false);
|
|
123
|
+
throw err;
|
|
124
|
+
}
|
|
125
|
+
setData(() => result.data);
|
|
126
|
+
setLoading(false);
|
|
127
|
+
return result.data;
|
|
128
|
+
} catch (err) {
|
|
129
|
+
if (err instanceof AggregatedError) setError(err);
|
|
130
|
+
setLoading(false);
|
|
131
|
+
throw err;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
return [execute, {
|
|
60
135
|
get data() {
|
|
61
136
|
return data();
|
|
62
137
|
},
|
|
@@ -65,15 +140,28 @@ const createMutation = (document) => {
|
|
|
65
140
|
},
|
|
66
141
|
get error() {
|
|
67
142
|
return error();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
};
|
|
143
|
+
}
|
|
144
|
+
}];
|
|
71
145
|
};
|
|
72
146
|
|
|
73
147
|
//#endregion
|
|
74
148
|
//#region src/create-fragment.ts
|
|
75
|
-
const createFragment = (
|
|
76
|
-
|
|
149
|
+
const createFragment = (fragment, fragmentRef, options) => {
|
|
150
|
+
const client = useClient();
|
|
151
|
+
const result = pipe(client.executeFragment(fragment, fragmentRef(), options?.()), peek);
|
|
152
|
+
if (result.data === void 0) throw new Error("Fragment data not found");
|
|
153
|
+
const [data, setData] = createSignal(result.data);
|
|
154
|
+
createEffect(() => {
|
|
155
|
+
const unsubscribe = pipe(client.executeFragment(fragment, fragmentRef(), options?.()), subscribe({ next: (result$1) => {
|
|
156
|
+
if (result$1.data !== void 0) setData(() => result$1.data);
|
|
157
|
+
} }));
|
|
158
|
+
onCleanup(() => {
|
|
159
|
+
unsubscribe();
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
return { get data() {
|
|
163
|
+
return data();
|
|
164
|
+
} };
|
|
77
165
|
};
|
|
78
166
|
|
|
79
167
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,39 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mearie/solid",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.4",
|
|
4
|
+
"description": "Type-safe, zero-overhead GraphQL client",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"graphql",
|
|
7
|
+
"graphql-client",
|
|
8
|
+
"typescript",
|
|
9
|
+
"codegen",
|
|
10
|
+
"cache"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/devunt/mearie#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/devunt/mearie/issues"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/devunt/mearie.git",
|
|
19
|
+
"directory": "packages/solid"
|
|
20
|
+
},
|
|
21
|
+
"funding": {
|
|
22
|
+
"type": "github",
|
|
23
|
+
"url": "https://github.com/sponsors/devunt"
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"author": "Bae Junehyeon <finn@penxle.io>",
|
|
4
27
|
"sideEffects": false,
|
|
5
28
|
"type": "module",
|
|
6
|
-
"
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.js",
|
|
33
|
+
"require": "./dist/index.cjs"
|
|
34
|
+
},
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
7
37
|
"files": [
|
|
8
38
|
"dist",
|
|
9
39
|
"package.json",
|
|
10
40
|
"README.md"
|
|
11
41
|
],
|
|
12
42
|
"dependencies": {
|
|
13
|
-
"@mearie/
|
|
43
|
+
"@mearie/core": "0.0.1-next.4"
|
|
14
44
|
},
|
|
15
45
|
"devDependencies": {
|
|
16
|
-
"solid-js": "^1.9.
|
|
17
|
-
"tsdown": "^0.15.
|
|
46
|
+
"solid-js": "^1.9.10",
|
|
47
|
+
"tsdown": "^0.15.12",
|
|
48
|
+
"typescript": "^5.9.3"
|
|
18
49
|
},
|
|
19
50
|
"peerDependencies": {
|
|
20
51
|
"solid-js": "^1.8.0"
|
|
21
52
|
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"bun": ">=1.2.0",
|
|
55
|
+
"deno": ">=2.2.0",
|
|
56
|
+
"node": ">=20.0.0"
|
|
57
|
+
},
|
|
22
58
|
"publishConfig": {
|
|
23
59
|
"access": "public"
|
|
24
60
|
},
|
|
25
61
|
"scripts": {
|
|
26
62
|
"build": "tsdown",
|
|
27
|
-
"
|
|
28
|
-
},
|
|
29
|
-
"exports": {
|
|
30
|
-
".": {
|
|
31
|
-
"types": "./dist/index.d.ts",
|
|
32
|
-
"import": "./dist/index.js",
|
|
33
|
-
"require": "./dist/index.cjs"
|
|
34
|
-
},
|
|
35
|
-
"./package.json": "./package.json"
|
|
63
|
+
"typecheck": "tsc"
|
|
36
64
|
},
|
|
65
|
+
"main": "./dist/index.cjs",
|
|
37
66
|
"module": "./dist/index.js",
|
|
38
67
|
"types": "./dist/index.d.ts"
|
|
39
68
|
}
|