buildgql 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Robert Ozimek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,375 @@
1
+ # buildgql
2
+
3
+ Type-safe GraphQL query builder, generated from your schema's introspection.
4
+
5
+ Write selections as plain TypeScript. Result types and operation variables are
6
+ both **inferred from what you selected** — no hand-written response types, no
7
+ `$name: String!` declarations.
8
+
9
+ ```ts
10
+ import { query, mutation, $, createClient } from './src/gql';
11
+
12
+ const client = createClient({ url: 'https://api.example.com/graphql' });
13
+
14
+ const Posts = query('Posts', ($, q) => [
15
+ q.posts((post) => [
16
+ post.id,
17
+ post.title,
18
+ post.author((author) => [author.id, author.firstName, author.lastName]),
19
+ ]),
20
+ ]);
21
+
22
+ const result = await client.execute(Posts);
23
+ // ^? { posts: { id: string; title: string; author: { id: string; firstName: string; lastName: string | null } }[] }
24
+ ```
25
+
26
+ Mutations infer their variables from where you used `$`:
27
+
28
+ ```ts
29
+ const CreateNewUser = mutation('CreateNewUser', ($, m) => [
30
+ m.createUser({ name: $.name, email: $.email }, (user) => [user.id, user.firstName]),
31
+ ]);
32
+
33
+ await client.execute(CreateNewUser, { name: 'John Smith', email: 'john@smith.com' });
34
+ // ^ typed as { name: string; email: string }
35
+ ```
36
+
37
+ `./src/gql` above is the generated module — see **Configure** below. `query`,
38
+ `mutation`, `$`, `v`, `on`, `spread`, `include`, `skip` and `createClient` are all
39
+ re-exported from it, so everyday code only needs that one import.
40
+
41
+ ## Install
42
+
43
+ ```bash
44
+ npm i buildgql
45
+ ```
46
+
47
+ Or run the generator without installing anything:
48
+
49
+ ```bash
50
+ npx buildgql generate # pnpm dlx buildgql generate, yarn dlx buildgql generate
51
+ ```
52
+
53
+ One caveat when you run it that way, and only if your `schema` points at an SDL
54
+ file (`.graphql`): parsing SDL needs `graphql`, which buildgql declares as an
55
+ _optional_ peer dependency and `npx` does not install. buildgql looks for it in
56
+ your project directory (the one holding `buildgql.config.*`, or whatever
57
+ `--config` names), so `npm i -D graphql` there is enough — you do not need to
58
+ install buildgql itself. A `schema` that is a URL or an `introspection.json` file
59
+ needs nothing extra.
60
+
61
+ Contributing? See [CONTRIBUTING.md](./CONTRIBUTING.md) for the naming, error, and
62
+ type-performance conventions this repo follows — `npm run check` enforces what's
63
+ mechanical (case shape, the `any` ban, the type-instantiation budget); the rest is
64
+ convention enforced by review.
65
+
66
+ ## Configure
67
+
68
+ Create `buildgql.config.mjs` — this works on **every** supported Node version,
69
+ including Node 20 in CI:
70
+
71
+ ```js
72
+ import { defineConfig } from 'buildgql/config';
73
+
74
+ export default defineConfig({
75
+ // a URL...
76
+ schema: 'https://api.example.com/graphql',
77
+ headers: { Authorization: `Bearer ${process.env.API_TOKEN}` },
78
+
79
+ // ...or a local file: './schema.graphql' or './introspection.json'
80
+
81
+ output: './src/gql',
82
+ // See "Custom scalars" below for object-typed scalars.
83
+ scalars: { DateTime: 'string', JSON: 'unknown' },
84
+
85
+ // 'buildgql' (default) | 'apollo' | 'urql' | 'none' — see "Using Apollo or urql"
86
+ client: 'buildgql',
87
+ });
88
+ ```
89
+
90
+ If you'd rather write `buildgql.config.ts` for the editor type-checking on
91
+ `defineConfig(...)`, that works too — but only on **Node >= 22.6 run with
92
+ `--experimental-strip-types`, or Node >= 23.6** (where native TypeScript
93
+ support is unflagged). On older Node, buildgql falls back to any
94
+ `buildgql.config.mjs`/`buildgql.config.js` also present; if none is present it
95
+ fails with an error telling you to add one or upgrade Node.
96
+
97
+ Then:
98
+
99
+ ```bash
100
+ npx buildgql generate
101
+ ```
102
+
103
+ ## Variables
104
+
105
+ `$.someArg` marks an argument as a variable. The variable is **named after the
106
+ argument** and typed from the schema:
107
+
108
+ ```ts
109
+ m.createUser({ name: $.name }, (user) => [user.id]);
110
+ // -> mutation ($name: String!) { createUser(name: $name) { id } }
111
+ ```
112
+
113
+ Two fields needing different variables for the same argument name would collide.
114
+ Name one explicitly with `v()`:
115
+
116
+ ```ts
117
+ import { v } from './src/gql';
118
+ q.post({ id: v('postId') }, (post) => [post.title]);
119
+ ```
120
+
121
+ Optional schema arguments produce optional variables — TypeScript handles the rest.
122
+
123
+ Enum arguments passed as literals print unquoted (`status: PUBLISHED`, not
124
+ `status: "PUBLISHED"`), _except_ when the enum is nested inside an input-object
125
+ literal (e.g. `{ filter: { status: 'PUBLISHED' } }`) — the printer has no view of
126
+ the input type graph at that depth, so it falls back to a quoted string there. If
127
+ you hit this, pass the value as a variable instead (`{ filter: $.filter }`); JSON
128
+ variable transport encodes enums correctly regardless of nesting.
129
+
130
+ ## Custom scalars
131
+
132
+ Every scalar outside GraphQL's built-in five (`ID`, `String`, `Int`, `Float`, `Boolean`)
133
+ needs an entry in `scalars`, or it generates as `unknown` (and buildgql warns, by name,
134
+ when it does). The simplest entry is a raw TypeScript type expression, used in both
135
+ argument and result position:
136
+
137
+ ```js
138
+ scalars: { DateTime: 'string', JSON: 'unknown' }
139
+ ```
140
+
141
+ For scalars a single expression cannot express, an entry can be an object instead.
142
+
143
+ **Different types in and out.** A `DateTime` you may _pass_ as a `Date` but always _read
144
+ back_ as an ISO string:
145
+
146
+ ```js
147
+ scalars: { DateTime: { input: 'string | Date', output: 'string' } }
148
+ ```
149
+
150
+ **A type you already have.** `from` imports it; the generated module gets an
151
+ `import type` line, so there is no runtime dependency on that module:
152
+
153
+ ```js
154
+ scalars: { Money: { name: 'Money', from: './src/types/money' } }
155
+ ```
156
+
157
+ **A type declared inline.** `declare` is the right-hand side of a type alias; buildgql
158
+ emits `export type <name> = ...` into the generated module, so your own code can import
159
+ the type from there too:
160
+
161
+ ```js
162
+ scalars: {
163
+ JSON: {
164
+ name: 'JSONValue',
165
+ declare: 'string | number | boolean | null | JSONValue[] | { [k: string]: JSONValue }',
166
+ },
167
+ }
168
+ ```
169
+
170
+ `name` can be combined with `input`/`output` to widen one position while still importing
171
+ or declaring the type: `{ name: 'Money', from: './money', input: 'Money | string' }`.
172
+ `from` and `declare` are mutually exclusive.
173
+
174
+ ### Where does `from` point?
175
+
176
+ A **package specifier** (`type-fest`, `@myorg/domain-types`) is emitted verbatim.
177
+
178
+ A **relative or absolute path** is written against _your config file_ — the same as
179
+ `schema` and `output` — and buildgql rewrites it to be relative to `output`. With
180
+ `output: './src/gql'`, a `from` of `'./src/types/money'` is emitted as `'../types/money'`.
181
+ Extensions are preserved exactly as written, so `nodenext` projects can write
182
+ `'./src/types/money.js'`.
183
+
184
+ **Publishing the generated module as an npm package?** (Generating in the backend repo
185
+ during CI and shipping an SDK to your frontends is a common setup.) A relative path
186
+ points at source files that will not exist inside the published package, so use one of:
187
+
188
+ - **`declare`** — the type is inlined into the generated module. Nothing to resolve, no
189
+ dependency to declare. This is the safest default for a published SDK.
190
+ - **a package specifier** — `from: '@myorg/domain-types'`. Resolves from inside the
191
+ published package, provided that package is a dependency of it.
192
+
193
+ buildgql prints the modules the generated file imports scalar types from, so you can
194
+ eyeball a mis-pointed path at generate time. It does not check that they resolve — that
195
+ still surfaces at your consumers' `tsc`.
196
+
197
+ ### What buildgql will refuse
198
+
199
+ The config is validated before anything is generated: an unknown key (`ouput`), a `name`
200
+ that isn't a bare identifier (ASCII letters/digits/`_`/`$`, not starting with a digit), or
201
+ a `name` that is a reserved word or a predefined TypeScript type name (`default`, `class`,
202
+ `string`, `void`, and the like) — both are rejected before generation rather than surfacing
203
+ as a syntax error in a generated file. Also refused: `from` and `declare` together, `name`
204
+ and `from`/`declare` used without one another (a `name` with neither, or a `from`/`declare`
205
+ with no `name` to hang it on), and a `from` containing a quote, backslash, or newline (it is
206
+ spliced into a quoted module specifier). It also refuses a `name` that collides with
207
+ something the generated module already binds — not just a schema type, an enum's `…Values`,
208
+ or a `…Fragment` helper, but also the runtime helpers and client bindings the generated
209
+ module itself imports (e.g. `query`, `mutation`, `$`, `v`) — rather than emitting a file
210
+ with a duplicate identifier in it.
211
+
212
+ ## Fragments, unions, directives
213
+
214
+ ```ts
215
+ import { on, spread, include, v, userFragment } from './src/gql';
216
+
217
+ const NameBits = userFragment('NameBits', (user) => [user.firstName, user.lastName]);
218
+
219
+ query('Feed', ($, q) => [
220
+ q.users((user) => [user.id, spread(NameBits)]),
221
+ q.pet((pet) => [on('Dog', Dog, (dog) => [dog.breed]), on('Cat', Cat, (cat) => [cat.lives])]),
222
+ q.me((me) => [include(me.email, v('withEmail'))]),
223
+ ]);
224
+ ```
225
+
226
+ `on()` yields a discriminated union that narrows on `__typename`.
227
+ `include()`/`skip()` make the result field optional, and their condition must be a
228
+ literal `boolean` or `v('name')` — `$.name` cannot name a directive condition,
229
+ since directives have no argument key to take the name from.
230
+
231
+ ## Subscriptions
232
+
233
+ ```ts
234
+ import { createClient, sseTransport } from 'buildgql/client';
235
+
236
+ const client = createClient({
237
+ url: 'https://api.example.com/graphql',
238
+ subscriptions: sseTransport({ url: 'https://api.example.com/graphql' }),
239
+ });
240
+
241
+ for await (const msg of client.subscribe(Messages)) {
242
+ console.log(msg);
243
+ }
244
+ ```
245
+
246
+ `wsTransport()` speaks the `graphql-ws` protocol if your server uses WebSockets.
247
+ Per-subscription `headers` (the third argument to `client.subscribe`) are honoured
248
+ by `sseTransport` but **cannot** be sent by `wsTransport` — the WebSocket API has no
249
+ per-message header mechanism. Authenticate WebSocket subscriptions via
250
+ `connectionParams` instead, which travels in the `connection_init` message body.
251
+ The generated module only exports `subscription` when your schema declares a
252
+ `Subscription` root type — build subscription operations with it the same way
253
+ you build queries and mutations with `query`/`mutation`.
254
+
255
+ ## Using Apollo or urql
256
+
257
+ buildgql's own `createClient` is the default, but the generated operations are just
258
+ documents plus inferred types — they run through any GraphQL client. Set `client`
259
+ in your config and the generated module re-exports that client's adapter instead
260
+ of `createClient`:
261
+
262
+ ```js
263
+ export default defineConfig({
264
+ schema: 'https://api.example.com/graphql',
265
+ client: 'apollo', // or 'urql'
266
+ });
267
+ ```
268
+
269
+ **Apollo Client:**
270
+
271
+ ```ts
272
+ import { query, mutation, apolloDocument, toApolloQuery, toApolloMutation } from './src/gql';
273
+ import { useQuery } from '@apollo/client';
274
+
275
+ const UserById = query('UserById', ($, q) => [q.user({ id: $.id }, (user) => [user.id, user.firstName])]);
276
+ const CreateUser = mutation('CreateUser', ($, m) => [m.createUser({ name: $.name }, (user) => [user.id])]);
277
+
278
+ // Imperative API — the adapter returns Apollo's options object verbatim.
279
+ const { data } = await apolloClient.query(toApolloQuery(UserById, { id: '7' }));
280
+ // ^? { user: { id: string; firstName: string } }
281
+
282
+ await apolloClient.mutate(toApolloMutation(CreateUser, { name: 'Ada' }));
283
+
284
+ // Hooks take the document positionally, so pass `apolloDocument(...)`.
285
+ const { data: hookData } = useQuery(apolloDocument(UserById), { variables: { id: '7' } });
286
+ ```
287
+
288
+ `toApolloQuery` also covers `client.watchQuery()` and `client.subscribe()`, which
289
+ take the same `{ query, variables }` shape. Passing a mutation to `toApolloQuery`
290
+ (or a query to `toApolloMutation`) throws — Apollo keys those options differently.
291
+
292
+ **urql:**
293
+
294
+ ```ts
295
+ import { query, mutation, toUrqlArgs, urqlDocument } from './src/gql';
296
+ import { useQuery, useMutation } from 'urql';
297
+
298
+ const UserById = query('UserById', ($, q) => [q.user({ id: $.id }, (user) => [user.id, user.firstName])]);
299
+ const CreateUser = mutation('CreateUser', ($, m) => [m.createUser({ name: $.name }, (user) => [user.id])]);
300
+
301
+ // urql's useQuery/useSubscription take { query, variables }; useMutation and the
302
+ // positional client methods take the document on its own — use urqlDocument for those.
303
+ const [result] = useQuery(toUrqlArgs(UserById, { id: '7' }));
304
+ // ^? { data?: { user: { id: string; firstName: string } } }
305
+
306
+ const [, createUser] = useMutation(urqlDocument(CreateUser));
307
+ await urqlClient.query(urqlDocument(UserById), { id: '7' }).toPromise();
308
+ ```
309
+
310
+ Every adapter is built on a `TypedDocumentNode<Result, Variables>` — the same phantom-typed
311
+ node Apollo and urql already understand. `apolloDocument`/`urqlDocument` return one directly;
312
+ `toApolloQuery`/`toApolloMutation`/`toUrqlArgs` return a `{ query, variables }` (or
313
+ `{ mutation, variables }`) object whose document field is one — so `data` and `variables` are
314
+ typed end-to-end with no extra generics at the call site.
315
+
316
+ Variables follow the same rule as `client.execute`: required schema arguments make the
317
+ `vars` argument mandatory, all-optional ones make it omissible.
318
+
319
+ You can also import the adapters directly without touching your config:
320
+
321
+ ```ts
322
+ import { toApolloQuery } from 'buildgql/adapters/apollo';
323
+ import { toUrqlArgs } from 'buildgql/adapters/urql';
324
+ ```
325
+
326
+ Adapters need the `graphql` package installed — they parse the printed document into
327
+ the AST these clients require. If it isn't installed, the import fails with Node's
328
+ `ERR_MODULE_NOT_FOUND` (`Cannot find package 'graphql'`) rather than a `buildgql:` message
329
+ — the adapters import it statically so the adapter functions can stay synchronous. Setting
330
+ `client: 'none'` binds no client at all, if you want to wire one up yourself.
331
+
332
+ ## Relay
333
+
334
+ Relay is **not** supported, and no adapter is planned.
335
+
336
+ Relay's store does not consume GraphQL documents at runtime. It requires
337
+ `ConcreteRequest` artifacts emitted ahead of time by relay-compiler — a normalization
338
+ AST, hashed identifiers, and a fragment-per-component model that the compiler derives
339
+ from source files it has scanned. buildgql builds its documents at runtime from
340
+ TypeScript selections, so there is nothing for relay-compiler to read and nothing for
341
+ the store to normalize against.
342
+
343
+ If you use Relay, use its own compiler. buildgql and Relay solve the same problem in
344
+ incompatible ways.
345
+
346
+ ## Requirements
347
+
348
+ - TypeScript **>= 5.4** with `"strict": true`
349
+ - Node **>= 18** to install and run the generated client/CLI in general.
350
+ Loading a **`.ts`** config file specifically needs Node's native TypeScript
351
+ support: **>= 22.6 with `--experimental-strip-types`, or >= 23.6**. Use
352
+ `buildgql.config.mjs` (see **Configure** above) if you're on an older Node —
353
+ it works everywhere Node >= 18 does.
354
+ - `graphql` if you point `schema` at an SDL file, **or** if you use an Apollo/urql
355
+ adapter (`client: 'apollo' | 'urql'`, or a direct `buildgql/adapters/*` import) —
356
+ the adapters parse the printed document into the AST those clients expect. URL and
357
+ `.json` introspection sources with the default client need no extra dependency.
358
+
359
+ ### Known limitation: `noUncheckedIndexedAccess`
360
+
361
+ `$.argName` does not type-check in projects that enable TypeScript's
362
+ `noUncheckedIndexedAccess`. The `$` proxy is typed as an index signature, so under that
363
+ flag every read widens to `VarMarker | undefined`, which the argument types reject.
364
+
365
+ Use the explicit form instead — it is unaffected:
366
+
367
+ ```ts
368
+ import { v } from 'buildgql';
369
+
370
+ const UserById = query('UserById', ($, q) => [q.user({ id: v('id') }, (user) => [user.name])]);
371
+ ```
372
+
373
+ ## License
374
+
375
+ MIT
@@ -0,0 +1,23 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+ var _chunkBM7L4MCFcjs = require('../chunk-BM7L4MCF.cjs');
6
+
7
+ // src/adapters/apollo.ts
8
+ function apolloDocument(op) {
9
+ return _chunkBM7L4MCFcjs.toDocument.call(void 0, op);
10
+ }
11
+ function toApolloQuery(op, ...rest) {
12
+ _chunkBM7L4MCFcjs.assertKind.call(void 0, op, ["query", "subscription"], "toApolloQuery");
13
+ return { query: _chunkBM7L4MCFcjs.toDocument.call(void 0, op), variables: _chunkBM7L4MCFcjs.variablesOf.call(void 0, rest) };
14
+ }
15
+ function toApolloMutation(op, ...rest) {
16
+ _chunkBM7L4MCFcjs.assertKind.call(void 0, op, ["mutation"], "toApolloMutation");
17
+ return { mutation: _chunkBM7L4MCFcjs.toDocument.call(void 0, op), variables: _chunkBM7L4MCFcjs.variablesOf.call(void 0, rest) };
18
+ }
19
+
20
+
21
+
22
+
23
+ exports.apolloDocument = apolloDocument; exports.toApolloMutation = toApolloMutation; exports.toApolloQuery = toApolloQuery;
@@ -0,0 +1,28 @@
1
+ import { O as Operation, V as VarsArg } from '../operation-DxbEION8.cjs';
2
+ import { T as TypedDocumentNode } from '../document-BZ9RdxXB.cjs';
3
+ import 'graphql';
4
+
5
+ /** Options for `apolloClient.query()`, `.watchQuery()` and `.subscribe()`. */
6
+ interface ApolloQueryArgs<R, V> {
7
+ readonly query: TypedDocumentNode<R, V>;
8
+ readonly variables: V;
9
+ }
10
+ /** Options for `apolloClient.mutate()`. */
11
+ interface ApolloMutationArgs<R, V> {
12
+ readonly mutation: TypedDocumentNode<R, V>;
13
+ readonly variables: V;
14
+ }
15
+ /**
16
+ * The operation as a typed Apollo document. Use this for the React hooks, which take the
17
+ * document positionally: `useQuery(apolloDocument(Op), { variables })`.
18
+ */
19
+ declare function apolloDocument<R, V>(op: Operation<R, V>): TypedDocumentNode<R, V>;
20
+ /**
21
+ * `{ query, variables }` for `apolloClient.query()`. Subscriptions are accepted too —
22
+ * Apollo's `client.subscribe()` takes the same `query` key.
23
+ */
24
+ declare function toApolloQuery<R, V>(op: Operation<R, V>, ...rest: VarsArg<V>): ApolloQueryArgs<R, V>;
25
+ /** `{ mutation, variables }` for `apolloClient.mutate()`. */
26
+ declare function toApolloMutation<R, V>(op: Operation<R, V>, ...rest: VarsArg<V>): ApolloMutationArgs<R, V>;
27
+
28
+ export { type ApolloMutationArgs, type ApolloQueryArgs, TypedDocumentNode, apolloDocument, toApolloMutation, toApolloQuery };
@@ -0,0 +1,28 @@
1
+ import { O as Operation, V as VarsArg } from '../operation-DxbEION8.js';
2
+ import { T as TypedDocumentNode } from '../document-BZ9RdxXB.js';
3
+ import 'graphql';
4
+
5
+ /** Options for `apolloClient.query()`, `.watchQuery()` and `.subscribe()`. */
6
+ interface ApolloQueryArgs<R, V> {
7
+ readonly query: TypedDocumentNode<R, V>;
8
+ readonly variables: V;
9
+ }
10
+ /** Options for `apolloClient.mutate()`. */
11
+ interface ApolloMutationArgs<R, V> {
12
+ readonly mutation: TypedDocumentNode<R, V>;
13
+ readonly variables: V;
14
+ }
15
+ /**
16
+ * The operation as a typed Apollo document. Use this for the React hooks, which take the
17
+ * document positionally: `useQuery(apolloDocument(Op), { variables })`.
18
+ */
19
+ declare function apolloDocument<R, V>(op: Operation<R, V>): TypedDocumentNode<R, V>;
20
+ /**
21
+ * `{ query, variables }` for `apolloClient.query()`. Subscriptions are accepted too —
22
+ * Apollo's `client.subscribe()` takes the same `query` key.
23
+ */
24
+ declare function toApolloQuery<R, V>(op: Operation<R, V>, ...rest: VarsArg<V>): ApolloQueryArgs<R, V>;
25
+ /** `{ mutation, variables }` for `apolloClient.mutate()`. */
26
+ declare function toApolloMutation<R, V>(op: Operation<R, V>, ...rest: VarsArg<V>): ApolloMutationArgs<R, V>;
27
+
28
+ export { type ApolloMutationArgs, type ApolloQueryArgs, TypedDocumentNode, apolloDocument, toApolloMutation, toApolloQuery };
@@ -0,0 +1,23 @@
1
+ import {
2
+ assertKind,
3
+ toDocument,
4
+ variablesOf
5
+ } from "../chunk-SNFCCROD.js";
6
+
7
+ // src/adapters/apollo.ts
8
+ function apolloDocument(op) {
9
+ return toDocument(op);
10
+ }
11
+ function toApolloQuery(op, ...rest) {
12
+ assertKind(op, ["query", "subscription"], "toApolloQuery");
13
+ return { query: toDocument(op), variables: variablesOf(rest) };
14
+ }
15
+ function toApolloMutation(op, ...rest) {
16
+ assertKind(op, ["mutation"], "toApolloMutation");
17
+ return { mutation: toDocument(op), variables: variablesOf(rest) };
18
+ }
19
+ export {
20
+ apolloDocument,
21
+ toApolloMutation,
22
+ toApolloQuery
23
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunkBM7L4MCFcjs = require('../chunk-BM7L4MCF.cjs');
5
+
6
+ // src/adapters/urql.ts
7
+ function urqlDocument(op) {
8
+ return _chunkBM7L4MCFcjs.toDocument.call(void 0, op);
9
+ }
10
+ function toUrqlArgs(op, ...rest) {
11
+ return { query: _chunkBM7L4MCFcjs.toDocument.call(void 0, op), variables: _chunkBM7L4MCFcjs.variablesOf.call(void 0, rest) };
12
+ }
13
+
14
+
15
+
16
+ exports.toUrqlArgs = toUrqlArgs; exports.urqlDocument = urqlDocument;
@@ -0,0 +1,26 @@
1
+ import { O as Operation, V as VarsArg } from '../operation-DxbEION8.cjs';
2
+ import { T as TypedDocumentNode } from '../document-BZ9RdxXB.cjs';
3
+ import 'graphql';
4
+
5
+ /**
6
+ * Arguments for urql's `useQuery`/`useSubscription`. urql uses the `query` key for every
7
+ * operation kind, mutations included, so there is one shape here rather than Apollo's two.
8
+ */
9
+ interface UrqlArgs<R, V> {
10
+ readonly query: TypedDocumentNode<R, V>;
11
+ readonly variables: V;
12
+ }
13
+ /**
14
+ * The operation as a typed urql document. Use this where urql takes the document
15
+ * positionally: `client.query(urqlDocument(Op), vars)`, `useMutation(urqlDocument(Op))`.
16
+ */
17
+ declare function urqlDocument<R, V>(op: Operation<R, V>): TypedDocumentNode<R, V>;
18
+ /**
19
+ * `{ query, variables }` for `useQuery(...)` / `useSubscription(...)`.
20
+ *
21
+ * No `assertKind` here, unlike the Apollo adapter: urql uses the `query` key for every
22
+ * operation kind, so there is no wrong kind to reject.
23
+ */
24
+ declare function toUrqlArgs<R, V>(op: Operation<R, V>, ...rest: VarsArg<V>): UrqlArgs<R, V>;
25
+
26
+ export { TypedDocumentNode, type UrqlArgs, toUrqlArgs, urqlDocument };
@@ -0,0 +1,26 @@
1
+ import { O as Operation, V as VarsArg } from '../operation-DxbEION8.js';
2
+ import { T as TypedDocumentNode } from '../document-BZ9RdxXB.js';
3
+ import 'graphql';
4
+
5
+ /**
6
+ * Arguments for urql's `useQuery`/`useSubscription`. urql uses the `query` key for every
7
+ * operation kind, mutations included, so there is one shape here rather than Apollo's two.
8
+ */
9
+ interface UrqlArgs<R, V> {
10
+ readonly query: TypedDocumentNode<R, V>;
11
+ readonly variables: V;
12
+ }
13
+ /**
14
+ * The operation as a typed urql document. Use this where urql takes the document
15
+ * positionally: `client.query(urqlDocument(Op), vars)`, `useMutation(urqlDocument(Op))`.
16
+ */
17
+ declare function urqlDocument<R, V>(op: Operation<R, V>): TypedDocumentNode<R, V>;
18
+ /**
19
+ * `{ query, variables }` for `useQuery(...)` / `useSubscription(...)`.
20
+ *
21
+ * No `assertKind` here, unlike the Apollo adapter: urql uses the `query` key for every
22
+ * operation kind, so there is no wrong kind to reject.
23
+ */
24
+ declare function toUrqlArgs<R, V>(op: Operation<R, V>, ...rest: VarsArg<V>): UrqlArgs<R, V>;
25
+
26
+ export { TypedDocumentNode, type UrqlArgs, toUrqlArgs, urqlDocument };
@@ -0,0 +1,16 @@
1
+ import {
2
+ toDocument,
3
+ variablesOf
4
+ } from "../chunk-SNFCCROD.js";
5
+
6
+ // src/adapters/urql.ts
7
+ function urqlDocument(op) {
8
+ return toDocument(op);
9
+ }
10
+ function toUrqlArgs(op, ...rest) {
11
+ return { query: toDocument(op), variables: variablesOf(rest) };
12
+ }
13
+ export {
14
+ toUrqlArgs,
15
+ urqlDocument
16
+ };