@m1212e/rumble 0.15.2 → 0.15.3

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/out/index.cjs CHANGED
@@ -48,7 +48,7 @@ __pothos_plugin_smart_subscriptions = __toESM(__pothos_plugin_smart_subscription
48
48
  let graphql_scalars = require("graphql-scalars");
49
49
 
50
50
  //#region lib/client/generate/client.ts
51
- function generateClient({ apiUrl, rumbleImportPath, useExternalUrqlClient, availableSubscriptions, schemaPath }) {
51
+ function generateClient({ apiUrl, rumbleImportPath, useExternalUrqlClient, availableSubscriptions, schemaPath, forceReactivity }) {
52
52
  const imports = [];
53
53
  let code = "";
54
54
  if (typeof useExternalUrqlClient === "string") imports.push(`import { urqlClient } from "${useExternalUrqlClient}";`);
@@ -57,6 +57,8 @@ function generateClient({ apiUrl, rumbleImportPath, useExternalUrqlClient, avail
57
57
  imports.push(`import { nativeDateExchange } from '${rumbleImportPath}';`);
58
58
  imports.push(`import { schema } from '${schemaPath}';`);
59
59
  imports.push(`import { makeLiveQuery, makeMutation, makeSubscription, makeQuery } from '${rumbleImportPath}';`);
60
+ const forceReactivityValueString = typeof forceReactivity === "boolean" && forceReactivity ? "true" : "";
61
+ const forceReactivityFieldString = forceReactivityValueString !== "" ? `forceReactivity: ${forceReactivityValueString}` : "";
60
62
  code += `
61
63
  export const defaultOptions: ConstructorParameters<Client>[0] = {
62
64
  url: "${apiUrl ?? "PLEASE PROVIDE A URL WHEN GENERATING OR IMPORT AN EXTERNAL URQL CLIENT"}",
@@ -79,27 +81,31 @@ export const client = {
79
81
  * Assumes that the query and subscription return the same fields as per default when using the rumble query helpers.
80
82
  * If no subscription with the same name exists, this will just be a query.
81
83
  */
82
- liveQuery: makeLiveQuery<Query>({
84
+ liveQuery: makeLiveQuery<Query${`, ${forceReactivityValueString}`}>({
83
85
  urqlClient,
84
86
  availableSubscriptions: new Set([${availableSubscriptions.values().toArray().map((value) => `"${value}"`).join(", ")}]),
87
+ ${forceReactivityFieldString}
85
88
  }),
86
89
  /**
87
90
  * A mutation that can be used to e.g. create, update or delete data.
88
91
  */
89
- mutate: makeMutation<Mutation>({
92
+ mutate: makeMutation<Mutation${`, ${forceReactivityValueString}`}>({
90
93
  urqlClient,
94
+ ${forceReactivityFieldString}
91
95
  }),
92
96
  /**
93
97
  * A continuous stream of results that updates when the server sends new data.
94
98
  */
95
- subscribe: makeSubscription<Subscription>({
99
+ subscribe: makeSubscription<Subscription${`, ${forceReactivityValueString}`}>({
96
100
  urqlClient,
101
+ ${forceReactivityFieldString}
97
102
  }),
98
103
  /**
99
104
  * A one-time fetch of data.
100
105
  */
101
- query: makeQuery<Query>({
106
+ query: makeQuery<Query${`, ${forceReactivityValueString}`}>({
102
107
  urqlClient,
108
+ ${forceReactivityValueString !== "" ? `forceReactivity: ${forceReactivityValueString}` : ""}
103
109
  }),
104
110
  }`;
105
111
  return {
@@ -206,7 +212,7 @@ function makeStringLiteralUnionFromEnum(enumType) {
206
212
 
207
213
  //#endregion
208
214
  //#region lib/client/generate/generate.ts
209
- async function generateFromSchema({ outputPath, schema, rumbleImportPath = "@m1212e/rumble", apiUrl, useExternalUrqlClient = false, removeExisting = true }) {
215
+ async function generateFromSchema({ outputPath, schema, rumbleImportPath = "@m1212e/rumble", apiUrl, useExternalUrqlClient = false, removeExisting = true, forceReactivity }) {
210
216
  if (removeExisting) try {
211
217
  await (0, node_fs_promises.access)(outputPath);
212
218
  await (0, node_fs_promises.rm)(outputPath, {
@@ -236,7 +242,8 @@ export type ${key} = ${rep};
236
242
  schemaPath: `./${schemaFileName}`,
237
243
  useExternalUrqlClient,
238
244
  rumbleImportPath,
239
- availableSubscriptions: new Set(Object.keys(schema.getSubscriptionType()?.getFields() || {}))
245
+ availableSubscriptions: new Set(Object.keys(schema.getSubscriptionType()?.getFields() || {})),
246
+ forceReactivity
240
247
  });
241
248
  imports.push(...c.imports);
242
249
  code += c.code;
@@ -247,7 +254,7 @@ export const schema = ${(0, devalue.uneval)((0, __urql_introspection.minifyIntro
247
254
  //#endregion
248
255
  //#region lib/client/request.ts
249
256
  const argsKey = "__args";
250
- function makeGraphQLQueryRequest({ queryName, input, client, enableSubscription = false }) {
257
+ function makeGraphQLQueryRequest({ queryName, input, client, enableSubscription = false, forceReactivity }) {
251
258
  const otwQueryName = `${(0, es_toolkit.capitalize)(queryName)}Query`;
252
259
  const argsString = stringifyArgumentObjectToGraphqlList(input?.[argsKey] ?? {});
253
260
  const operationString = (operationVerb) => `${operationVerb} ${otwQueryName} { ${queryName}${argsString} ${input ? `{ ${stringifySelection(input)} }` : ""}}`;
@@ -257,13 +264,13 @@ function makeGraphQLQueryRequest({ queryName, input, client, enableSubscription
257
264
  if (!data && v.error) throw v.error;
258
265
  return data;
259
266
  }), (0, wonka.onPush)((data) => {
260
- if (typeof data === "object" && data !== null) Object.assign(awaitedReturnValueReference, data);
267
+ if (typeof data === "object" && data !== null && typeof forceReactivity === "boolean" && forceReactivity) Object.assign(awaitedReturnValueReference, data);
261
268
  }));
262
269
  const observable = (0, wonka.toObservable)(source);
263
270
  const promise = (0, wonka.toPromise)((0, wonka.pipe)(source, (0, wonka.take)(1), (0, wonka.map)((data) => {
264
- if (typeof data === "object" && data !== null) {
271
+ Object.assign(awaitedReturnValueReference, observable);
272
+ if (typeof data === "object" && data !== null && typeof forceReactivity === "boolean" && forceReactivity) {
265
273
  Object.assign(awaitedReturnValueReference, data);
266
- Object.assign(awaitedReturnValueReference, observable);
267
274
  return awaitedReturnValueReference;
268
275
  }
269
276
  return data;
@@ -271,7 +278,7 @@ function makeGraphQLQueryRequest({ queryName, input, client, enableSubscription
271
278
  Object.assign(promise, observable);
272
279
  return promise;
273
280
  }
274
- function makeGraphQLMutationRequest({ mutationName, input, client }) {
281
+ function makeGraphQLMutationRequest({ mutationName, input, client, forceReactivity }) {
275
282
  const otwMutationName = `${(0, es_toolkit.capitalize)(mutationName)}Mutation`;
276
283
  const argsString = stringifyArgumentObjectToGraphqlList(input[argsKey] ?? {});
277
284
  const response = (0, wonka.pipe)(client.mutation(`mutation ${otwMutationName} { ${mutationName}${argsString} { ${stringifySelection(input)} }}`, {}), (0, wonka.map)((v) => {
@@ -284,7 +291,7 @@ function makeGraphQLMutationRequest({ mutationName, input, client }) {
284
291
  Object.assign(promise, observable);
285
292
  return promise;
286
293
  }
287
- function makeGraphQLSubscriptionRequest({ subscriptionName, input, client }) {
294
+ function makeGraphQLSubscriptionRequest({ subscriptionName, input, client, forceReactivity }) {
288
295
  const otwSubscriptionName = `${(0, es_toolkit.capitalize)(subscriptionName)}Subscription`;
289
296
  const argsString = stringifyArgumentObjectToGraphqlList(input[argsKey] ?? {});
290
297
  return (0, wonka.pipe)(client.subscription(`subscription ${otwSubscriptionName} { ${subscriptionName}${argsString} { ${stringifySelection(input)} }}`, {}), (0, wonka.map)((v) => {
@@ -330,14 +337,15 @@ function stringifyArgumentValue(arg) {
330
337
 
331
338
  //#endregion
332
339
  //#region lib/client/liveQuery.ts
333
- function makeLiveQuery({ urqlClient, availableSubscriptions }) {
340
+ function makeLiveQuery({ urqlClient, availableSubscriptions, forceReactivity }) {
334
341
  return new Proxy({}, { get: (_target, prop) => {
335
342
  return (input) => {
336
343
  return makeGraphQLQueryRequest({
337
344
  queryName: prop,
338
345
  input,
339
346
  client: urqlClient,
340
- enableSubscription: availableSubscriptions.has(prop)
347
+ enableSubscription: availableSubscriptions.has(prop),
348
+ forceReactivity
341
349
  });
342
350
  };
343
351
  } });
@@ -345,13 +353,14 @@ function makeLiveQuery({ urqlClient, availableSubscriptions }) {
345
353
 
346
354
  //#endregion
347
355
  //#region lib/client/mutation.ts
348
- function makeMutation({ urqlClient }) {
356
+ function makeMutation({ urqlClient, forceReactivity }) {
349
357
  return new Proxy({}, { get: (_target, prop) => {
350
358
  return (input) => {
351
359
  return makeGraphQLMutationRequest({
352
360
  mutationName: prop,
353
361
  input,
354
- client: urqlClient
362
+ client: urqlClient,
363
+ forceReactivity
355
364
  });
356
365
  };
357
366
  } });
@@ -426,14 +435,15 @@ const nativeDateExchange = ({ client, forward }) => {
426
435
 
427
436
  //#endregion
428
437
  //#region lib/client/query.ts
429
- function makeQuery({ urqlClient }) {
438
+ function makeQuery({ urqlClient, forceReactivity }) {
430
439
  return new Proxy({}, { get: (_target, prop) => {
431
440
  return (input) => {
432
441
  return makeGraphQLQueryRequest({
433
442
  queryName: prop,
434
443
  input,
435
444
  client: urqlClient,
436
- enableSubscription: false
445
+ enableSubscription: false,
446
+ forceReactivity
437
447
  });
438
448
  };
439
449
  } });
@@ -441,13 +451,14 @@ function makeQuery({ urqlClient }) {
441
451
 
442
452
  //#endregion
443
453
  //#region lib/client/subscription.ts
444
- function makeSubscription({ urqlClient }) {
454
+ function makeSubscription({ urqlClient, forceReactivity }) {
445
455
  return new Proxy({}, { get: (_target, prop) => {
446
456
  return (input) => {
447
457
  return makeGraphQLSubscriptionRequest({
448
458
  subscriptionName: prop,
449
459
  input,
450
- client: urqlClient
460
+ client: urqlClient,
461
+ forceReactivity
451
462
  });
452
463
  };
453
464
  } });
@@ -1143,7 +1154,7 @@ const createWhereArgImplementer = ({ db, schemaBuilder, enumImplementer }) => {
1143
1154
  //#endregion
1144
1155
  //#region lib/client/client.ts
1145
1156
  const clientCreatorImplementer = ({ builtSchema }) => {
1146
- const clientCreator = async ({ apiUrl, outputPath, rumbleImportPath, useExternalUrqlClient, removeExisting }) => {
1157
+ const clientCreator = async ({ apiUrl, outputPath, rumbleImportPath, useExternalUrqlClient, removeExisting, forceReactivity }) => {
1147
1158
  if (process.env.NODE_ENV !== "development") console.warn("Running rumble client generation in non development mode. Are you sure this is correct?");
1148
1159
  await generateFromSchema({
1149
1160
  schema: builtSchema(),
@@ -1151,7 +1162,8 @@ const clientCreatorImplementer = ({ builtSchema }) => {
1151
1162
  rumbleImportPath,
1152
1163
  apiUrl,
1153
1164
  useExternalUrqlClient,
1154
- removeExisting
1165
+ removeExisting,
1166
+ forceReactivity
1155
1167
  });
1156
1168
  };
1157
1169
  return clientCreator;