@mearie/solid 0.0.0-next-20260228035926
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/LICENSE +20 -0
- package/README.md +70 -0
- package/dist/index.cjs +192 -0
- package/dist/index.d.cts +114 -0
- package/dist/index.d.mts +114 -0
- package/dist/index.mjs +182 -0
- package/package.json +73 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2025 Bae Junehyeon
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# @mearie/solid
|
|
2
|
+
|
|
3
|
+
Solid bindings for Mearie GraphQL client.
|
|
4
|
+
|
|
5
|
+
This package provides Solid primitives, components, and the GraphQL client
|
|
6
|
+
runtime for using Mearie in Solid applications.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install -D mearie
|
|
12
|
+
npm install @mearie/solid
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
The `mearie` package provides build-time code generation, while `@mearie/solid`
|
|
16
|
+
includes the runtime client and Solid-specific primitives.
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
First, create a client and wrap your app with the provider:
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
// src/App.tsx
|
|
24
|
+
import { type Component } from 'solid-js';
|
|
25
|
+
import { createClient, httpExchange, cacheExchange, dedupExchange, ClientProvider } from '@mearie/solid';
|
|
26
|
+
import { schema } from '$mearie';
|
|
27
|
+
|
|
28
|
+
const client = createClient({
|
|
29
|
+
schema,
|
|
30
|
+
exchanges: [dedupExchange(), cacheExchange(), httpExchange({ url: 'https://api.example.com/graphql' })],
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const App: Component = () => {
|
|
34
|
+
return <ClientProvider client={client}>{/* Your app components */}</ClientProvider>;
|
|
35
|
+
};
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Then use it in your components:
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
// src/components/UserProfile.tsx
|
|
42
|
+
import { type Component } from 'solid-js';
|
|
43
|
+
import { graphql } from '$mearie';
|
|
44
|
+
import { createQuery } from '@mearie/solid';
|
|
45
|
+
|
|
46
|
+
interface UserProfileProps {
|
|
47
|
+
userId: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const UserProfile: Component<UserProfileProps> = (props) => {
|
|
51
|
+
const query = createQuery(
|
|
52
|
+
graphql(`
|
|
53
|
+
query GetUser($id: ID!) {
|
|
54
|
+
user(id: $id) {
|
|
55
|
+
id
|
|
56
|
+
name
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
`),
|
|
60
|
+
() => ({ id: props.userId }),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
if (query.loading) return <div>Loading...</div>;
|
|
64
|
+
return <h1>{query.data.user.name}</h1>;
|
|
65
|
+
};
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Documentation
|
|
69
|
+
|
|
70
|
+
Full documentation is available at <https://mearie.dev/frameworks/solid>.
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _mearie_core = require("@mearie/core");
|
|
3
|
+
let solid_js = require("solid-js");
|
|
4
|
+
let _mearie_core_stream = require("@mearie/core/stream");
|
|
5
|
+
|
|
6
|
+
//#region src/client-provider.tsx
|
|
7
|
+
const ClientContext = (0, solid_js.createContext)();
|
|
8
|
+
const ClientProvider = (props) => {
|
|
9
|
+
return <ClientContext.Provider value={props.client}>{props.children}</ClientContext.Provider>;
|
|
10
|
+
};
|
|
11
|
+
const useClient = () => {
|
|
12
|
+
const client = (0, solid_js.useContext)(ClientContext);
|
|
13
|
+
if (!client) throw new Error("useClient must be used within ClientProvider");
|
|
14
|
+
return client;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/create-query.ts
|
|
19
|
+
const createQuery = ((query, variables, options) => {
|
|
20
|
+
const client = useClient();
|
|
21
|
+
const initialOpts = options?.();
|
|
22
|
+
const [data, setData] = (0, solid_js.createSignal)(initialOpts?.initialData);
|
|
23
|
+
const [loading, setLoading] = (0, solid_js.createSignal)(!initialOpts?.skip && !initialOpts?.initialData);
|
|
24
|
+
const [error, setError] = (0, solid_js.createSignal)();
|
|
25
|
+
let unsubscribe = null;
|
|
26
|
+
let initialized = false;
|
|
27
|
+
const execute = () => {
|
|
28
|
+
unsubscribe?.();
|
|
29
|
+
if (options?.()?.skip) return;
|
|
30
|
+
if (!initialized && initialOpts?.initialData) setLoading(true);
|
|
31
|
+
initialized = true;
|
|
32
|
+
setError(void 0);
|
|
33
|
+
unsubscribe = (0, _mearie_core_stream.pipe)(client.executeQuery(query, typeof variables === "function" ? variables() : variables, options?.()), (0, _mearie_core_stream.subscribe)({ next: (result) => {
|
|
34
|
+
if (result.errors && result.errors.length > 0) {
|
|
35
|
+
setError(new _mearie_core.AggregatedError(result.errors));
|
|
36
|
+
setLoading(false);
|
|
37
|
+
} else {
|
|
38
|
+
setData(() => result.data);
|
|
39
|
+
setLoading(false);
|
|
40
|
+
setError(void 0);
|
|
41
|
+
}
|
|
42
|
+
} }));
|
|
43
|
+
};
|
|
44
|
+
const refetch = () => {
|
|
45
|
+
(0, solid_js.untrack)(execute);
|
|
46
|
+
};
|
|
47
|
+
(0, solid_js.createEffect)(() => {
|
|
48
|
+
execute();
|
|
49
|
+
(0, solid_js.onCleanup)(() => {
|
|
50
|
+
unsubscribe?.();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
return {
|
|
54
|
+
get data() {
|
|
55
|
+
return data();
|
|
56
|
+
},
|
|
57
|
+
get loading() {
|
|
58
|
+
return loading();
|
|
59
|
+
},
|
|
60
|
+
get error() {
|
|
61
|
+
return error();
|
|
62
|
+
},
|
|
63
|
+
refetch
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/create-subscription.ts
|
|
69
|
+
const createSubscription = (subscription, ...[variables, options]) => {
|
|
70
|
+
const client = useClient();
|
|
71
|
+
const [data, setData] = (0, solid_js.createSignal)();
|
|
72
|
+
const [loading, setLoading] = (0, solid_js.createSignal)(!options?.()?.skip);
|
|
73
|
+
const [error, setError] = (0, solid_js.createSignal)();
|
|
74
|
+
(0, solid_js.createEffect)(() => {
|
|
75
|
+
if (options?.()?.skip) return;
|
|
76
|
+
setLoading(true);
|
|
77
|
+
setError(void 0);
|
|
78
|
+
const unsubscribe = (0, _mearie_core_stream.pipe)(client.executeSubscription(subscription, typeof variables === "function" ? variables() : variables, options?.()), (0, _mearie_core_stream.subscribe)({ next: (result) => {
|
|
79
|
+
if (result.errors && result.errors.length > 0) {
|
|
80
|
+
const err = new _mearie_core.AggregatedError(result.errors);
|
|
81
|
+
setError(err);
|
|
82
|
+
setLoading(false);
|
|
83
|
+
options?.()?.onError?.(err);
|
|
84
|
+
} else {
|
|
85
|
+
const resultData = result.data;
|
|
86
|
+
setData(() => resultData);
|
|
87
|
+
setLoading(false);
|
|
88
|
+
setError(void 0);
|
|
89
|
+
options?.()?.onData?.(resultData);
|
|
90
|
+
}
|
|
91
|
+
} }));
|
|
92
|
+
(0, solid_js.onCleanup)(() => {
|
|
93
|
+
unsubscribe();
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
return {
|
|
97
|
+
get data() {
|
|
98
|
+
return data();
|
|
99
|
+
},
|
|
100
|
+
get loading() {
|
|
101
|
+
return loading();
|
|
102
|
+
},
|
|
103
|
+
get error() {
|
|
104
|
+
return error();
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/create-mutation.ts
|
|
111
|
+
const createMutation = (mutation) => {
|
|
112
|
+
const client = useClient();
|
|
113
|
+
const [data, setData] = (0, solid_js.createSignal)();
|
|
114
|
+
const [loading, setLoading] = (0, solid_js.createSignal)(false);
|
|
115
|
+
const [error, setError] = (0, solid_js.createSignal)();
|
|
116
|
+
const execute = async (variables, options) => {
|
|
117
|
+
setLoading(true);
|
|
118
|
+
setError(void 0);
|
|
119
|
+
try {
|
|
120
|
+
const result = await (0, _mearie_core_stream.pipe)(client.executeMutation(mutation, variables, options), (0, _mearie_core_stream.take)(1), _mearie_core_stream.collect);
|
|
121
|
+
if (result.errors && result.errors.length > 0) {
|
|
122
|
+
const err = new _mearie_core.AggregatedError(result.errors);
|
|
123
|
+
setError(err);
|
|
124
|
+
setLoading(false);
|
|
125
|
+
throw err;
|
|
126
|
+
}
|
|
127
|
+
setData(() => result.data);
|
|
128
|
+
setLoading(false);
|
|
129
|
+
return result.data;
|
|
130
|
+
} catch (err) {
|
|
131
|
+
if (err instanceof _mearie_core.AggregatedError) setError(err);
|
|
132
|
+
setLoading(false);
|
|
133
|
+
throw err;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
return [execute, {
|
|
137
|
+
get data() {
|
|
138
|
+
return data();
|
|
139
|
+
},
|
|
140
|
+
get loading() {
|
|
141
|
+
return loading();
|
|
142
|
+
},
|
|
143
|
+
get error() {
|
|
144
|
+
return error();
|
|
145
|
+
}
|
|
146
|
+
}];
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/create-fragment.ts
|
|
151
|
+
const createFragment = ((fragment, fragmentRef, options) => {
|
|
152
|
+
const client = useClient();
|
|
153
|
+
const initialRef = fragmentRef();
|
|
154
|
+
let initialData;
|
|
155
|
+
if (initialRef == null) initialData = null;
|
|
156
|
+
else {
|
|
157
|
+
const result = (0, _mearie_core_stream.pipe)(client.executeFragment(fragment, initialRef, options?.()), _mearie_core_stream.peek);
|
|
158
|
+
if (result.data === void 0) throw new Error("Fragment data not found");
|
|
159
|
+
initialData = result.data;
|
|
160
|
+
}
|
|
161
|
+
const [data, setData] = (0, solid_js.createSignal)(initialData);
|
|
162
|
+
(0, solid_js.createEffect)(() => {
|
|
163
|
+
const currentRef = fragmentRef();
|
|
164
|
+
if (currentRef == null) {
|
|
165
|
+
setData(() => null);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const unsubscribe = (0, _mearie_core_stream.pipe)(client.executeFragment(fragment, currentRef, options?.()), (0, _mearie_core_stream.subscribe)({ next: (result) => {
|
|
169
|
+
if (result.data !== void 0) setData(() => result.data);
|
|
170
|
+
} }));
|
|
171
|
+
(0, solid_js.onCleanup)(() => {
|
|
172
|
+
unsubscribe();
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
return { get data() {
|
|
176
|
+
return data();
|
|
177
|
+
} };
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
//#endregion
|
|
181
|
+
exports.ClientProvider = ClientProvider;
|
|
182
|
+
exports.createFragment = createFragment;
|
|
183
|
+
exports.createMutation = createMutation;
|
|
184
|
+
exports.createQuery = createQuery;
|
|
185
|
+
exports.createSubscription = createSubscription;
|
|
186
|
+
exports.useClient = useClient;
|
|
187
|
+
Object.keys(_mearie_core).forEach(function (k) {
|
|
188
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
189
|
+
enumerable: true,
|
|
190
|
+
get: function () { return _mearie_core[k]; }
|
|
191
|
+
});
|
|
192
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { AggregatedError, Artifact, Client, DataOf, FragmentOptions, FragmentRefs, MutationOptions, QueryOptions, SchemaMeta, SubscriptionOptions, VariablesOf } from "@mearie/core";
|
|
2
|
+
import { Accessor, JSX } from "solid-js";
|
|
3
|
+
export * from "@mearie/core";
|
|
4
|
+
|
|
5
|
+
//#region src/client-provider.d.ts
|
|
6
|
+
type ClientProviderProps<TMeta extends SchemaMeta = SchemaMeta> = {
|
|
7
|
+
client: Client<TMeta>;
|
|
8
|
+
children: JSX.Element;
|
|
9
|
+
};
|
|
10
|
+
declare const ClientProvider: <TMeta extends SchemaMeta = SchemaMeta>(props: ClientProviderProps<TMeta>) => JSX.Element;
|
|
11
|
+
declare const useClient: <TMeta extends SchemaMeta = SchemaMeta>() => Client<TMeta>;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/create-query.d.ts
|
|
14
|
+
type CreateQueryOptions<T extends Artifact<'query'> = Artifact<'query'>> = QueryOptions<T> & {
|
|
15
|
+
skip?: boolean;
|
|
16
|
+
};
|
|
17
|
+
type Query<T extends Artifact<'query'>> = {
|
|
18
|
+
data: undefined;
|
|
19
|
+
loading: true;
|
|
20
|
+
error: undefined;
|
|
21
|
+
refetch: () => void;
|
|
22
|
+
} | {
|
|
23
|
+
data: DataOf<T>;
|
|
24
|
+
loading: false;
|
|
25
|
+
error: undefined;
|
|
26
|
+
refetch: () => void;
|
|
27
|
+
} | {
|
|
28
|
+
data: DataOf<T> | undefined;
|
|
29
|
+
loading: false;
|
|
30
|
+
error: AggregatedError;
|
|
31
|
+
refetch: () => void;
|
|
32
|
+
};
|
|
33
|
+
type DefinedQuery<T extends Artifact<'query'>> = {
|
|
34
|
+
data: DataOf<T>;
|
|
35
|
+
loading: true;
|
|
36
|
+
error: undefined;
|
|
37
|
+
refetch: () => void;
|
|
38
|
+
} | {
|
|
39
|
+
data: DataOf<T>;
|
|
40
|
+
loading: false;
|
|
41
|
+
error: undefined;
|
|
42
|
+
refetch: () => void;
|
|
43
|
+
} | {
|
|
44
|
+
data: DataOf<T>;
|
|
45
|
+
loading: false;
|
|
46
|
+
error: AggregatedError;
|
|
47
|
+
refetch: () => void;
|
|
48
|
+
};
|
|
49
|
+
type CreateQueryFn = {
|
|
50
|
+
<T extends Artifact<'query'>>(query: T, variables: Accessor<VariablesOf<T>> | undefined, options: Accessor<CreateQueryOptions<T> & {
|
|
51
|
+
initialData: DataOf<T>;
|
|
52
|
+
}>): DefinedQuery<T>;
|
|
53
|
+
<T extends Artifact<'query'>>(query: T, ...[variables, options]: VariablesOf<T> extends Record<string, never> ? [undefined?, Accessor<CreateQueryOptions<T>>?] : [Accessor<VariablesOf<T>>, Accessor<CreateQueryOptions<T>>?]): Query<T>;
|
|
54
|
+
};
|
|
55
|
+
declare const createQuery: CreateQueryFn;
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/create-subscription.d.ts
|
|
58
|
+
type Subscription<T extends Artifact<'subscription'>> = {
|
|
59
|
+
data: undefined;
|
|
60
|
+
loading: true;
|
|
61
|
+
error: undefined;
|
|
62
|
+
} | {
|
|
63
|
+
data: DataOf<T> | undefined;
|
|
64
|
+
loading: false;
|
|
65
|
+
error: undefined;
|
|
66
|
+
} | {
|
|
67
|
+
data: DataOf<T> | undefined;
|
|
68
|
+
loading: false;
|
|
69
|
+
error: AggregatedError;
|
|
70
|
+
};
|
|
71
|
+
type CreateSubscriptionOptions<T extends Artifact<'subscription'>> = SubscriptionOptions & {
|
|
72
|
+
skip?: boolean;
|
|
73
|
+
onData?: (data: DataOf<T>) => void;
|
|
74
|
+
onError?: (error: AggregatedError) => void;
|
|
75
|
+
};
|
|
76
|
+
declare const createSubscription: <T extends Artifact<"subscription">>(subscription: T, ...[variables, options]: VariablesOf<T> extends Record<string, never> ? [undefined?, Accessor<CreateSubscriptionOptions<T>>?] : [Accessor<VariablesOf<T>>, Accessor<CreateSubscriptionOptions<T>>?]) => Subscription<T>;
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/create-mutation.d.ts
|
|
79
|
+
type MutationResult<T extends Artifact<'mutation'>> = {
|
|
80
|
+
data: undefined;
|
|
81
|
+
loading: true;
|
|
82
|
+
error: undefined;
|
|
83
|
+
} | {
|
|
84
|
+
data: DataOf<T> | undefined;
|
|
85
|
+
loading: false;
|
|
86
|
+
error: undefined;
|
|
87
|
+
} | {
|
|
88
|
+
data: DataOf<T> | undefined;
|
|
89
|
+
loading: false;
|
|
90
|
+
error: AggregatedError;
|
|
91
|
+
};
|
|
92
|
+
type CreateMutationOptions = MutationOptions;
|
|
93
|
+
type Mutation<T extends Artifact<'mutation'>> = [(...[variables, options]: VariablesOf<T> extends Record<string, never> ? [undefined?, CreateMutationOptions?] : [VariablesOf<T>, CreateMutationOptions?]) => Promise<DataOf<T>>, MutationResult<T>];
|
|
94
|
+
declare const createMutation: <T extends Artifact<"mutation">>(mutation: T) => Mutation<T>;
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/create-fragment.d.ts
|
|
97
|
+
type CreateFragmentOptions = FragmentOptions;
|
|
98
|
+
type Fragment<T extends Artifact<'fragment'>> = {
|
|
99
|
+
data: DataOf<T>;
|
|
100
|
+
};
|
|
101
|
+
type FragmentList<T extends Artifact<'fragment'>> = {
|
|
102
|
+
data: DataOf<T>[];
|
|
103
|
+
};
|
|
104
|
+
type OptionalFragment<T extends Artifact<'fragment'>> = {
|
|
105
|
+
data: DataOf<T> | null;
|
|
106
|
+
};
|
|
107
|
+
type CreateFragmentFn = {
|
|
108
|
+
<T extends Artifact<'fragment'>>(fragment: T, fragmentRef: Accessor<FragmentRefs<T['name']>[]>, options?: Accessor<CreateFragmentOptions>): FragmentList<T>;
|
|
109
|
+
<T extends Artifact<'fragment'>>(fragment: T, fragmentRef: Accessor<FragmentRefs<T['name']>>, options?: Accessor<CreateFragmentOptions>): Fragment<T>;
|
|
110
|
+
<T extends Artifact<'fragment'>>(fragment: T, fragmentRef: Accessor<FragmentRefs<T['name']> | null | undefined>, options?: Accessor<CreateFragmentOptions>): OptionalFragment<T>;
|
|
111
|
+
};
|
|
112
|
+
declare const createFragment: CreateFragmentFn;
|
|
113
|
+
//#endregion
|
|
114
|
+
export { ClientProvider, type ClientProviderProps, type CreateFragmentOptions, type CreateMutationOptions, type CreateQueryOptions, type CreateSubscriptionOptions, type DefinedQuery, type Fragment, type FragmentList, type Mutation, type MutationResult, type OptionalFragment, type Query, type Subscription, createFragment, createMutation, createQuery, createSubscription, useClient };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { AggregatedError, Artifact, Client, DataOf, FragmentOptions, FragmentRefs, MutationOptions, QueryOptions, SchemaMeta, SubscriptionOptions, VariablesOf } from "@mearie/core";
|
|
2
|
+
import { Accessor, JSX } from "solid-js";
|
|
3
|
+
export * from "@mearie/core";
|
|
4
|
+
|
|
5
|
+
//#region src/client-provider.d.ts
|
|
6
|
+
type ClientProviderProps<TMeta extends SchemaMeta = SchemaMeta> = {
|
|
7
|
+
client: Client<TMeta>;
|
|
8
|
+
children: JSX.Element;
|
|
9
|
+
};
|
|
10
|
+
declare const ClientProvider: <TMeta extends SchemaMeta = SchemaMeta>(props: ClientProviderProps<TMeta>) => JSX.Element;
|
|
11
|
+
declare const useClient: <TMeta extends SchemaMeta = SchemaMeta>() => Client<TMeta>;
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/create-query.d.ts
|
|
14
|
+
type CreateQueryOptions<T extends Artifact<'query'> = Artifact<'query'>> = QueryOptions<T> & {
|
|
15
|
+
skip?: boolean;
|
|
16
|
+
};
|
|
17
|
+
type Query<T extends Artifact<'query'>> = {
|
|
18
|
+
data: undefined;
|
|
19
|
+
loading: true;
|
|
20
|
+
error: undefined;
|
|
21
|
+
refetch: () => void;
|
|
22
|
+
} | {
|
|
23
|
+
data: DataOf<T>;
|
|
24
|
+
loading: false;
|
|
25
|
+
error: undefined;
|
|
26
|
+
refetch: () => void;
|
|
27
|
+
} | {
|
|
28
|
+
data: DataOf<T> | undefined;
|
|
29
|
+
loading: false;
|
|
30
|
+
error: AggregatedError;
|
|
31
|
+
refetch: () => void;
|
|
32
|
+
};
|
|
33
|
+
type DefinedQuery<T extends Artifact<'query'>> = {
|
|
34
|
+
data: DataOf<T>;
|
|
35
|
+
loading: true;
|
|
36
|
+
error: undefined;
|
|
37
|
+
refetch: () => void;
|
|
38
|
+
} | {
|
|
39
|
+
data: DataOf<T>;
|
|
40
|
+
loading: false;
|
|
41
|
+
error: undefined;
|
|
42
|
+
refetch: () => void;
|
|
43
|
+
} | {
|
|
44
|
+
data: DataOf<T>;
|
|
45
|
+
loading: false;
|
|
46
|
+
error: AggregatedError;
|
|
47
|
+
refetch: () => void;
|
|
48
|
+
};
|
|
49
|
+
type CreateQueryFn = {
|
|
50
|
+
<T extends Artifact<'query'>>(query: T, variables: Accessor<VariablesOf<T>> | undefined, options: Accessor<CreateQueryOptions<T> & {
|
|
51
|
+
initialData: DataOf<T>;
|
|
52
|
+
}>): DefinedQuery<T>;
|
|
53
|
+
<T extends Artifact<'query'>>(query: T, ...[variables, options]: VariablesOf<T> extends Record<string, never> ? [undefined?, Accessor<CreateQueryOptions<T>>?] : [Accessor<VariablesOf<T>>, Accessor<CreateQueryOptions<T>>?]): Query<T>;
|
|
54
|
+
};
|
|
55
|
+
declare const createQuery: CreateQueryFn;
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/create-subscription.d.ts
|
|
58
|
+
type Subscription<T extends Artifact<'subscription'>> = {
|
|
59
|
+
data: undefined;
|
|
60
|
+
loading: true;
|
|
61
|
+
error: undefined;
|
|
62
|
+
} | {
|
|
63
|
+
data: DataOf<T> | undefined;
|
|
64
|
+
loading: false;
|
|
65
|
+
error: undefined;
|
|
66
|
+
} | {
|
|
67
|
+
data: DataOf<T> | undefined;
|
|
68
|
+
loading: false;
|
|
69
|
+
error: AggregatedError;
|
|
70
|
+
};
|
|
71
|
+
type CreateSubscriptionOptions<T extends Artifact<'subscription'>> = SubscriptionOptions & {
|
|
72
|
+
skip?: boolean;
|
|
73
|
+
onData?: (data: DataOf<T>) => void;
|
|
74
|
+
onError?: (error: AggregatedError) => void;
|
|
75
|
+
};
|
|
76
|
+
declare const createSubscription: <T extends Artifact<"subscription">>(subscription: T, ...[variables, options]: VariablesOf<T> extends Record<string, never> ? [undefined?, Accessor<CreateSubscriptionOptions<T>>?] : [Accessor<VariablesOf<T>>, Accessor<CreateSubscriptionOptions<T>>?]) => Subscription<T>;
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/create-mutation.d.ts
|
|
79
|
+
type MutationResult<T extends Artifact<'mutation'>> = {
|
|
80
|
+
data: undefined;
|
|
81
|
+
loading: true;
|
|
82
|
+
error: undefined;
|
|
83
|
+
} | {
|
|
84
|
+
data: DataOf<T> | undefined;
|
|
85
|
+
loading: false;
|
|
86
|
+
error: undefined;
|
|
87
|
+
} | {
|
|
88
|
+
data: DataOf<T> | undefined;
|
|
89
|
+
loading: false;
|
|
90
|
+
error: AggregatedError;
|
|
91
|
+
};
|
|
92
|
+
type CreateMutationOptions = MutationOptions;
|
|
93
|
+
type Mutation<T extends Artifact<'mutation'>> = [(...[variables, options]: VariablesOf<T> extends Record<string, never> ? [undefined?, CreateMutationOptions?] : [VariablesOf<T>, CreateMutationOptions?]) => Promise<DataOf<T>>, MutationResult<T>];
|
|
94
|
+
declare const createMutation: <T extends Artifact<"mutation">>(mutation: T) => Mutation<T>;
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/create-fragment.d.ts
|
|
97
|
+
type CreateFragmentOptions = FragmentOptions;
|
|
98
|
+
type Fragment<T extends Artifact<'fragment'>> = {
|
|
99
|
+
data: DataOf<T>;
|
|
100
|
+
};
|
|
101
|
+
type FragmentList<T extends Artifact<'fragment'>> = {
|
|
102
|
+
data: DataOf<T>[];
|
|
103
|
+
};
|
|
104
|
+
type OptionalFragment<T extends Artifact<'fragment'>> = {
|
|
105
|
+
data: DataOf<T> | null;
|
|
106
|
+
};
|
|
107
|
+
type CreateFragmentFn = {
|
|
108
|
+
<T extends Artifact<'fragment'>>(fragment: T, fragmentRef: Accessor<FragmentRefs<T['name']>[]>, options?: Accessor<CreateFragmentOptions>): FragmentList<T>;
|
|
109
|
+
<T extends Artifact<'fragment'>>(fragment: T, fragmentRef: Accessor<FragmentRefs<T['name']>>, options?: Accessor<CreateFragmentOptions>): Fragment<T>;
|
|
110
|
+
<T extends Artifact<'fragment'>>(fragment: T, fragmentRef: Accessor<FragmentRefs<T['name']> | null | undefined>, options?: Accessor<CreateFragmentOptions>): OptionalFragment<T>;
|
|
111
|
+
};
|
|
112
|
+
declare const createFragment: CreateFragmentFn;
|
|
113
|
+
//#endregion
|
|
114
|
+
export { ClientProvider, type ClientProviderProps, type CreateFragmentOptions, type CreateMutationOptions, type CreateQueryOptions, type CreateSubscriptionOptions, type DefinedQuery, type Fragment, type FragmentList, type Mutation, type MutationResult, type OptionalFragment, type Query, type Subscription, createFragment, createMutation, createQuery, createSubscription, useClient };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { AggregatedError } from "@mearie/core";
|
|
2
|
+
import { createContext, createEffect, createSignal, onCleanup, untrack, useContext } from "solid-js";
|
|
3
|
+
import { collect, peek, pipe, subscribe, take } from "@mearie/core/stream";
|
|
4
|
+
|
|
5
|
+
export * from "@mearie/core"
|
|
6
|
+
|
|
7
|
+
//#region src/client-provider.tsx
|
|
8
|
+
const ClientContext = createContext();
|
|
9
|
+
const ClientProvider = (props) => {
|
|
10
|
+
return <ClientContext.Provider value={props.client}>{props.children}</ClientContext.Provider>;
|
|
11
|
+
};
|
|
12
|
+
const useClient = () => {
|
|
13
|
+
const client = useContext(ClientContext);
|
|
14
|
+
if (!client) throw new Error("useClient must be used within ClientProvider");
|
|
15
|
+
return client;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/create-query.ts
|
|
20
|
+
const createQuery = ((query, variables, options) => {
|
|
21
|
+
const client = useClient();
|
|
22
|
+
const initialOpts = options?.();
|
|
23
|
+
const [data, setData] = createSignal(initialOpts?.initialData);
|
|
24
|
+
const [loading, setLoading] = createSignal(!initialOpts?.skip && !initialOpts?.initialData);
|
|
25
|
+
const [error, setError] = createSignal();
|
|
26
|
+
let unsubscribe = null;
|
|
27
|
+
let initialized = false;
|
|
28
|
+
const execute = () => {
|
|
29
|
+
unsubscribe?.();
|
|
30
|
+
if (options?.()?.skip) return;
|
|
31
|
+
if (!initialized && initialOpts?.initialData) setLoading(true);
|
|
32
|
+
initialized = true;
|
|
33
|
+
setError(void 0);
|
|
34
|
+
unsubscribe = pipe(client.executeQuery(query, typeof variables === "function" ? variables() : variables, options?.()), subscribe({ next: (result) => {
|
|
35
|
+
if (result.errors && result.errors.length > 0) {
|
|
36
|
+
setError(new AggregatedError(result.errors));
|
|
37
|
+
setLoading(false);
|
|
38
|
+
} else {
|
|
39
|
+
setData(() => result.data);
|
|
40
|
+
setLoading(false);
|
|
41
|
+
setError(void 0);
|
|
42
|
+
}
|
|
43
|
+
} }));
|
|
44
|
+
};
|
|
45
|
+
const refetch = () => {
|
|
46
|
+
untrack(execute);
|
|
47
|
+
};
|
|
48
|
+
createEffect(() => {
|
|
49
|
+
execute();
|
|
50
|
+
onCleanup(() => {
|
|
51
|
+
unsubscribe?.();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
get data() {
|
|
56
|
+
return data();
|
|
57
|
+
},
|
|
58
|
+
get loading() {
|
|
59
|
+
return loading();
|
|
60
|
+
},
|
|
61
|
+
get error() {
|
|
62
|
+
return error();
|
|
63
|
+
},
|
|
64
|
+
refetch
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/create-subscription.ts
|
|
70
|
+
const createSubscription = (subscription, ...[variables, options]) => {
|
|
71
|
+
const client = useClient();
|
|
72
|
+
const [data, setData] = createSignal();
|
|
73
|
+
const [loading, setLoading] = createSignal(!options?.()?.skip);
|
|
74
|
+
const [error, setError] = createSignal();
|
|
75
|
+
createEffect(() => {
|
|
76
|
+
if (options?.()?.skip) return;
|
|
77
|
+
setLoading(true);
|
|
78
|
+
setError(void 0);
|
|
79
|
+
const unsubscribe = pipe(client.executeSubscription(subscription, typeof variables === "function" ? variables() : variables, options?.()), subscribe({ next: (result) => {
|
|
80
|
+
if (result.errors && result.errors.length > 0) {
|
|
81
|
+
const err = new AggregatedError(result.errors);
|
|
82
|
+
setError(err);
|
|
83
|
+
setLoading(false);
|
|
84
|
+
options?.()?.onError?.(err);
|
|
85
|
+
} else {
|
|
86
|
+
const resultData = result.data;
|
|
87
|
+
setData(() => resultData);
|
|
88
|
+
setLoading(false);
|
|
89
|
+
setError(void 0);
|
|
90
|
+
options?.()?.onData?.(resultData);
|
|
91
|
+
}
|
|
92
|
+
} }));
|
|
93
|
+
onCleanup(() => {
|
|
94
|
+
unsubscribe();
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
get data() {
|
|
99
|
+
return data();
|
|
100
|
+
},
|
|
101
|
+
get loading() {
|
|
102
|
+
return loading();
|
|
103
|
+
},
|
|
104
|
+
get error() {
|
|
105
|
+
return error();
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/create-mutation.ts
|
|
112
|
+
const createMutation = (mutation) => {
|
|
113
|
+
const client = useClient();
|
|
114
|
+
const [data, setData] = createSignal();
|
|
115
|
+
const [loading, setLoading] = createSignal(false);
|
|
116
|
+
const [error, setError] = createSignal();
|
|
117
|
+
const execute = async (variables, options) => {
|
|
118
|
+
setLoading(true);
|
|
119
|
+
setError(void 0);
|
|
120
|
+
try {
|
|
121
|
+
const result = await pipe(client.executeMutation(mutation, variables, options), take(1), collect);
|
|
122
|
+
if (result.errors && result.errors.length > 0) {
|
|
123
|
+
const err = new AggregatedError(result.errors);
|
|
124
|
+
setError(err);
|
|
125
|
+
setLoading(false);
|
|
126
|
+
throw err;
|
|
127
|
+
}
|
|
128
|
+
setData(() => result.data);
|
|
129
|
+
setLoading(false);
|
|
130
|
+
return result.data;
|
|
131
|
+
} catch (err) {
|
|
132
|
+
if (err instanceof AggregatedError) setError(err);
|
|
133
|
+
setLoading(false);
|
|
134
|
+
throw err;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
return [execute, {
|
|
138
|
+
get data() {
|
|
139
|
+
return data();
|
|
140
|
+
},
|
|
141
|
+
get loading() {
|
|
142
|
+
return loading();
|
|
143
|
+
},
|
|
144
|
+
get error() {
|
|
145
|
+
return error();
|
|
146
|
+
}
|
|
147
|
+
}];
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/create-fragment.ts
|
|
152
|
+
const createFragment = ((fragment, fragmentRef, options) => {
|
|
153
|
+
const client = useClient();
|
|
154
|
+
const initialRef = fragmentRef();
|
|
155
|
+
let initialData;
|
|
156
|
+
if (initialRef == null) initialData = null;
|
|
157
|
+
else {
|
|
158
|
+
const result = pipe(client.executeFragment(fragment, initialRef, options?.()), peek);
|
|
159
|
+
if (result.data === void 0) throw new Error("Fragment data not found");
|
|
160
|
+
initialData = result.data;
|
|
161
|
+
}
|
|
162
|
+
const [data, setData] = createSignal(initialData);
|
|
163
|
+
createEffect(() => {
|
|
164
|
+
const currentRef = fragmentRef();
|
|
165
|
+
if (currentRef == null) {
|
|
166
|
+
setData(() => null);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const unsubscribe = pipe(client.executeFragment(fragment, currentRef, options?.()), subscribe({ next: (result) => {
|
|
170
|
+
if (result.data !== void 0) setData(() => result.data);
|
|
171
|
+
} }));
|
|
172
|
+
onCleanup(() => {
|
|
173
|
+
unsubscribe();
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
return { get data() {
|
|
177
|
+
return data();
|
|
178
|
+
} };
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
//#endregion
|
|
182
|
+
export { ClientProvider, createFragment, createMutation, createQuery, createSubscription, useClient };
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mearie/solid",
|
|
3
|
+
"version": "0.0.0-next-20260228035926",
|
|
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>",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"type": "module",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./dist/index.d.mts",
|
|
33
|
+
"default": "./dist/index.mjs"
|
|
34
|
+
},
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./dist/index.d.cts",
|
|
37
|
+
"default": "./dist/index.cjs"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"./package.json": "./package.json"
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist",
|
|
44
|
+
"package.json",
|
|
45
|
+
"README.md"
|
|
46
|
+
],
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@mearie/core": "0.0.0-next-20260228035926"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"solid-js": "^1.9.11",
|
|
52
|
+
"tsdown": "^0.20.3",
|
|
53
|
+
"typescript": "^5.9.3"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"solid-js": "^1.8.0"
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"bun": ">=1.2.0",
|
|
60
|
+
"deno": ">=2.2.0",
|
|
61
|
+
"node": ">=20.0.0"
|
|
62
|
+
},
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"access": "public"
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "tsdown",
|
|
68
|
+
"typecheck": "tsc"
|
|
69
|
+
},
|
|
70
|
+
"main": "./dist/index.cjs",
|
|
71
|
+
"module": "./dist/index.mjs",
|
|
72
|
+
"types": "./dist/index.d.mts"
|
|
73
|
+
}
|