@m1212e/rumble 0.12.19 → 0.12.21

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,27 +48,25 @@ __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, schema }) {
51
+ function generateClient({ apiUrl, rumbleImportPath, useExternalUrqlClient, availableSubscriptions, schemaPath }) {
52
52
  const imports = [];
53
53
  let code = "";
54
54
  if (typeof useExternalUrqlClient === "string") imports.push(`import { urqlClient } from "${useExternalUrqlClient}";`);
55
55
  imports.push(`import { Client, fetchExchange } from '@urql/core';`);
56
56
  imports.push(`import { cacheExchange } from '@urql/exchange-graphcache';`);
57
57
  imports.push(`import { nativeDateExchange } from '${rumbleImportPath}';`);
58
+ imports.push(`import { schema } from '${schemaPath}';`);
58
59
  imports.push(`import { makeLiveQuery, makeMutation, makeSubscription, makeQuery } from '${rumbleImportPath}';`);
59
60
  code += `
60
61
  export const defaultOptions: ConstructorParameters<Client>[0] = {
61
62
  url: "${apiUrl ?? "PLEASE PROVIDE A URL WHEN GENERATING OR IMPORT AN EXTERNAL URQL CLIENT"}",
62
63
  fetchSubscriptions: true,
63
- exchanges: [cacheExchange({
64
- // @ts-ignore
65
- schema: ${schema ? (0, devalue.uneval)((0, __urql_introspection.minifyIntrospectionQuery)((0, __urql_introspection.getIntrospectedSchema)(schema))) : "undefined"}
66
- }), nativeDateExchange, fetchExchange],
64
+ exchanges: [cacheExchange({ schema }), nativeDateExchange, fetchExchange],
67
65
  fetchOptions: {
68
66
  credentials: "include",
69
67
  },
70
68
  requestPolicy: "cache-and-network",
71
- }
69
+ }
72
70
  `;
73
71
  if (!useExternalUrqlClient) code += `
74
72
  const urqlClient = new Client(defaultOptions);
@@ -208,8 +206,8 @@ function makeStringLiteralUnionFromEnum(enumType) {
208
206
 
209
207
  //#endregion
210
208
  //#region lib/client/generate/generate.ts
211
- async function generateFromSchema({ outputPath, schema, rumbleImportPath = "@m1212e/rumble", apiUrl, useExternalUrqlClient = false }) {
212
- try {
209
+ async function generateFromSchema({ outputPath, schema, rumbleImportPath = "@m1212e/rumble", apiUrl, useExternalUrqlClient = false, removeExisting = true }) {
210
+ if (removeExisting) try {
213
211
  await (0, node_fs_promises.access)(outputPath);
214
212
  await (0, node_fs_promises.rm)(outputPath, {
215
213
  recursive: true,
@@ -232,16 +230,18 @@ async function generateFromSchema({ outputPath, schema, rumbleImportPath = "@m12
232
230
  export type ${key} = ${rep};
233
231
  `;
234
232
  }
233
+ const schemaFileName = "schema";
235
234
  const c = generateClient({
236
235
  apiUrl,
237
- schema,
236
+ schemaPath: `./${schemaFileName}`,
238
237
  useExternalUrqlClient,
239
238
  rumbleImportPath,
240
239
  availableSubscriptions: new Set(Object.keys(schema.getSubscriptionType()?.getFields() || {}))
241
240
  });
242
241
  imports.push(...c.imports);
243
242
  code += c.code;
244
- await (0, node_fs_promises.writeFile)((0, node_path.join)(outputPath, "client.ts"), `${imports.join("\n")}\n${code}`);
243
+ await Promise.all([(0, node_fs_promises.writeFile)((0, node_path.join)(outputPath, "client.ts"), `${imports.join("\n")}\n${code}`), (0, node_fs_promises.writeFile)((0, node_path.join)(outputPath, `${schemaFileName}.ts`), `// @ts-ignore
244
+ export const schema = ${(0, devalue.uneval)((0, __urql_introspection.minifyIntrospectionQuery)((0, __urql_introspection.getIntrospectedSchema)(schema)))}`)]);
245
245
  }
246
246
 
247
247
  //#endregion
@@ -251,21 +251,23 @@ function makeGraphQLQuery({ queryName, input, client, enableSubscription = false
251
251
  const otwQueryName = `${(0, es_toolkit.capitalize)(queryName)}Query`;
252
252
  const argsString = stringifyArgumentObjectToGraphqlList(input?.[argsKey] ?? {});
253
253
  const operationString = (operationVerb) => `${operationVerb} ${otwQueryName} { ${queryName}${argsString} ${input ? `{ ${stringifySelection(input)} }` : ""}}`;
254
- let awaitedReturnValueReference;
255
- const observable = (0, wonka.pipe)((0, wonka.merge)([client.query(operationString("query"), {}), enableSubscription ? client.subscription(operationString("subscription"), {}) : wonka.empty]), (0, wonka.map)((v) => {
254
+ const awaitedReturnValueReference = {};
255
+ const source = (0, wonka.pipe)((0, wonka.merge)([client.query(operationString("query"), {}), enableSubscription ? client.subscription(operationString("subscription"), {}) : wonka.empty]), wonka.share, (0, wonka.map)((v) => {
256
256
  const data = v.data?.[queryName];
257
257
  if (!data && v.error) throw v.error;
258
258
  return data;
259
259
  }), (0, wonka.onPush)((data) => {
260
- if (awaitedReturnValueReference) Object.assign(awaitedReturnValueReference, data);
261
- }), wonka.toObservable);
262
- const promise = new Promise((resolve) => {
263
- const unsub = observable.subscribe((v) => {
264
- unsub();
265
- awaitedReturnValueReference = Object.assign(v, observable);
266
- resolve(awaitedReturnValueReference);
267
- }).unsubscribe;
268
- });
260
+ if (typeof data === "object" && data !== null) Object.assign(awaitedReturnValueReference, data);
261
+ }));
262
+ const observable = (0, wonka.toObservable)(source);
263
+ const promise = (0, wonka.toPromise)((0, wonka.pipe)(source, (0, wonka.take)(1), (0, wonka.map)((data) => {
264
+ if (typeof data === "object" && data !== null) {
265
+ Object.assign(awaitedReturnValueReference, data);
266
+ Object.assign(awaitedReturnValueReference, observable);
267
+ return awaitedReturnValueReference;
268
+ }
269
+ return data;
270
+ })));
269
271
  Object.assign(promise, observable);
270
272
  return promise;
271
273
  }
@@ -278,10 +280,7 @@ function makeGraphQLMutation({ mutationName, input, client }) {
278
280
  return data;
279
281
  }));
280
282
  const observable = (0, wonka.toObservable)(response);
281
- const promise = (0, wonka.toPromise)(response).then((res) => {
282
- Object.assign(res, observable);
283
- return res;
284
- });
283
+ const promise = (0, wonka.toPromise)((0, wonka.pipe)(response, (0, wonka.take)(1)));
285
284
  Object.assign(promise, observable);
286
285
  return promise;
287
286
  }
@@ -316,6 +315,7 @@ function stringifyArgumentObjectToGraphqlList(args) {
316
315
  return `(${entries.map(([key, value]) => `${key}: ${stringifyArgumentValue(value)}`).join(", ")})`;
317
316
  }
318
317
  function stringifyArgumentValue(arg) {
318
+ if (arg === null) return "null";
319
319
  switch (typeof arg) {
320
320
  case "string": return `"${arg}"`;
321
321
  case "number": return `${arg}`;
@@ -1136,14 +1136,15 @@ const createWhereArgImplementer = ({ db, schemaBuilder, enumImplementer }) => {
1136
1136
  //#region lib/client/client.ts
1137
1137
  const clientCreatorImplementer = ({ builtSchema }) => {
1138
1138
  if (process.env.NODE_ENV !== "development") console.warn("Running rumble client generation in non development mode. Are you sure this is correct?");
1139
- const clientCreator = async ({ apiUrl, outputPath, rumbleImportPath, useExternalUrqlClient }) => {
1139
+ const clientCreator = async ({ apiUrl, outputPath, rumbleImportPath, useExternalUrqlClient, removeExisting }) => {
1140
1140
  if (process.env.NODE_ENV !== "development") console.warn("Running rumble client generation in non development mode. Are you sure this is correct?");
1141
1141
  await generateFromSchema({
1142
1142
  schema: builtSchema(),
1143
1143
  outputPath,
1144
1144
  rumbleImportPath,
1145
1145
  apiUrl,
1146
- useExternalUrqlClient
1146
+ useExternalUrqlClient,
1147
+ removeExisting
1147
1148
  });
1148
1149
  };
1149
1150
  return clientCreator;