@m1212e/rumble 0.16.7 → 0.16.12
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 +2 -0
- package/out/client/generate.cjs +1 -1
- package/out/client/generate.mjs +1 -1
- package/out/client.cjs +30 -26
- package/out/client.cjs.map +1 -1
- package/out/client.d.cts.map +1 -1
- package/out/client.d.mts.map +1 -1
- package/out/client.mjs +31 -27
- package/out/client.mjs.map +1 -1
- package/out/{generate-D3FWZlGu.cjs → generate-9zSO5f7n.cjs} +5 -3
- package/out/generate-9zSO5f7n.cjs.map +1 -0
- package/out/{generate-DcdqYHG4.mjs → generate-C3f0bYEP.mjs} +3 -1
- package/out/generate-C3f0bYEP.mjs.map +1 -0
- package/out/index.cjs +48 -61
- package/out/index.cjs.map +1 -1
- package/out/index.d.cts +2 -18
- package/out/index.d.cts.map +1 -1
- package/out/index.d.mts +2 -18
- package/out/index.d.mts.map +1 -1
- package/out/index.mjs +18 -35
- package/out/index.mjs.map +1 -1
- package/out/lazy-BrDkNRyV.cjs +32 -0
- package/out/lazy-BrDkNRyV.cjs.map +1 -0
- package/out/lazy-JdA7QgYA.mjs +26 -0
- package/out/lazy-JdA7QgYA.mjs.map +1 -0
- package/package.json +23 -22
- package/out/generate-D3FWZlGu.cjs.map +0 -1
- package/out/generate-DcdqYHG4.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-C3f0bYEP.mjs","names":["imports: string[]","code: string","imports: string[]"],"sources":["../lib/client/generate/client.ts","../lib/client/generate/tsRepresentation.ts","../lib/client/generate/generate.ts"],"sourcesContent":["export function generateClient({\n apiUrl,\n rumbleImportPath,\n useExternalUrqlClient,\n availableSubscriptions,\n schemaPath,\n forceReactivity,\n}: {\n rumbleImportPath: string;\n useExternalUrqlClient: string | boolean;\n apiUrl?: string;\n availableSubscriptions: Set<string>;\n schemaPath: string;\n forceReactivity?: boolean;\n}) {\n const imports: string[] = [];\n let code: string = \"\";\n\n if (typeof useExternalUrqlClient === \"string\") {\n imports.push(`import { urqlClient } from \"${useExternalUrqlClient}\";`);\n }\n\n imports.push(`import { Client, fetchExchange } from '@urql/core';`);\n imports.push(`import { cacheExchange } from '@urql/exchange-graphcache';`);\n imports.push(`import { nativeDateExchange } from '${rumbleImportPath}';`);\n imports.push(`import { schema } from '${schemaPath}';`);\n\n imports.push(\n `import { makeLiveQuery, makeMutation, makeSubscription, makeQuery } from '${rumbleImportPath}';`,\n );\n\n const forceReactivityFieldString =\n typeof forceReactivity === \"boolean\" && forceReactivity\n ? `\\n forceReactivity: true`\n : \"\";\n const forceReactivityTypeString =\n typeof forceReactivity === \"boolean\" && forceReactivity ? \", true\" : \"\";\n\n code += `\nexport const defaultOptions: ConstructorParameters<Client>[0] = {\n url: \"${apiUrl ?? \"PLEASE PROVIDE A URL WHEN GENERATING OR IMPORT AN EXTERNAL URQL CLIENT\"}\",\n fetchSubscriptions: true,\n exchanges: [cacheExchange({ schema }), nativeDateExchange, fetchExchange],\n fetchOptions: {\n credentials: \"include\",\n },\n requestPolicy: \"cache-and-network\",\n}\n`;\n\n if (!useExternalUrqlClient) {\n code += `\nconst urqlClient = new Client(defaultOptions);\n`;\n }\n\n code += `\nexport const client = {\n /**\n * A query and subscription combination. First queries and if exists, also subscribes to a subscription of the same name.\n * Combines the results of both, so the result is first the query result and then live updates from the subscription.\n * Assumes that the query and subscription return the same fields as per default when using the rumble query helpers.\n * If no subscription with the same name exists, this will just be a query.\n *\n * Internally, this does some magic to make the data reactive with Svelte's reactivity system. But it can be used with other frameworks as well.\n */\n liveQuery: makeLiveQuery<Query${forceReactivityTypeString}>({\n\t urqlClient,\n\t availableSubscriptions: new Set([${availableSubscriptions\n .values()\n .toArray()\n .map((value) => `\"${value}\"`)\n .join(\", \")}]),\n\t\tschema,${forceReactivityFieldString}\n }),\n /**\n * A mutation that can be used to e.g. create, update or delete data.\n */\n mutate: makeMutation<Mutation>({\n\t urqlClient,\n\t\tschema,\n }),\n /**\n * A continuous stream of results that updates when the server sends new data.\n */\n subscribe: makeSubscription<Subscription>({\n\t urqlClient,\n\t\tschema,\n }),\n /**\n * A one-time fetch of data.\n */\n query: makeQuery<Query${forceReactivityTypeString}>({\n\t urqlClient,\n\t\tschema,${forceReactivityFieldString}\n }),\n}`;\n\n return {\n imports,\n code,\n };\n}\n","import {\n type GraphQLArgument,\n GraphQLEnumType,\n GraphQLInputObjectType,\n type GraphQLInputType,\n GraphQLList,\n GraphQLNonNull,\n GraphQLObjectType,\n type GraphQLOutputType,\n GraphQLScalarType,\n} from \"graphql\";\n\ntype GraphQLType =\n | GraphQLObjectType<any, any>\n | GraphQLEnumType\n | GraphQLInputObjectType\n | GraphQLScalarType;\n\nexport function makeTSRepresentation(model: GraphQLType) {\n if (model instanceof GraphQLObjectType) {\n return makeTSTypeFromObject(model);\n } else if (model instanceof GraphQLScalarType) {\n return mapGraphqlScalarToTSTypeString(model);\n } else if (model instanceof GraphQLEnumType) {\n return makeStringLiteralUnionFromEnum(model);\n } else if (model instanceof GraphQLInputObjectType) {\n return makeTSTypeFromInputObject(model);\n }\n\n throw new Error(`Unknown model type: ${model}`);\n}\n\nfunction makeTSTypeFromObject(model: GraphQLObjectType) {\n const stringifiedFields = new Map<string, string>();\n for (const [key, value] of Object.entries(model.getFields())) {\n stringifiedFields.set(key, makeTSObjectTypeField(value.type, value.args));\n }\n\n return `{\n ${stringifiedFields\n .entries()\n .map(([key, value]) => `${key}: ${value}`)\n .toArray()\n .join(\",\\n \")} \n}`;\n}\n\nfunction makeTSTypeFromInputObject(model: GraphQLInputObjectType) {\n const stringifiedFields = new Map<string, string>();\n for (const [key, value] of Object.entries(model.getFields())) {\n stringifiedFields.set(key, makeTSInputObjectTypeField(value.type));\n }\n\n return `{\n ${stringifiedFields\n .entries()\n .map(\n ([key, value]) =>\n `${key}${value.includes(\"| undefined\") ? \"?\" : \"\"}: ${value}`,\n )\n .toArray()\n .join(\",\\n \")} \n}`;\n}\n\nfunction makeTSObjectTypeField(\n returnType: GraphQLOutputType,\n args?: readonly GraphQLArgument[],\n) {\n let isNonNullReturnType = false;\n let isList = false;\n\n for (let index = 0; index < 3; index++) {\n if (returnType instanceof GraphQLList) {\n isList = true;\n returnType = returnType.ofType;\n }\n\n if (returnType instanceof GraphQLNonNull) {\n isNonNullReturnType = true;\n returnType = returnType.ofType;\n }\n }\n\n let returnTypeString = (returnType as any).name;\n\n if (isList) {\n returnTypeString += \"[]\";\n }\n\n if (!isNonNullReturnType) {\n returnTypeString += \" | null\";\n }\n\n const isRelationType = returnType instanceof GraphQLObjectType;\n\n const argsStringMap = new Map<string, string>();\n\n for (const arg of args ?? []) {\n argsStringMap.set(arg.name, stringifyTSObjectArg(arg.type));\n }\n\n if (isRelationType) {\n const makePOptional = argsStringMap\n .entries()\n .every(([, value]) => value.includes(\"| undefined\"));\n const argsString =\n (args ?? []).length > 0\n ? `p${makePOptional ? \"?\" : \"\"}: {\n ${argsStringMap\n .entries()\n .map(\n ([key, value]) =>\n ` ${key}${value.includes(\"| undefined\") ? \"?\" : \"\"}: ${value}`,\n )\n .toArray()\n .join(\",\\n \")}\n }`\n : \"\";\n\n return `(${argsString}) => ${returnTypeString}`;\n } else {\n return returnTypeString;\n }\n}\n\nfunction makeTSInputObjectTypeField(returnType: GraphQLInputType) {\n let isNonNullReturnType = false;\n let isList = false;\n\n for (let index = 0; index < 3; index++) {\n if (returnType instanceof GraphQLList) {\n isList = true;\n returnType = returnType.ofType;\n }\n\n if (returnType instanceof GraphQLNonNull) {\n isNonNullReturnType = true;\n returnType = returnType.ofType;\n }\n }\n\n let returnTypeString = (returnType as any).name;\n\n if (isList) {\n returnTypeString += \"[]\";\n }\n\n if (!isNonNullReturnType) {\n returnTypeString += \" | null | undefined\";\n } else if (isList) {\n returnTypeString += \" | undefined\";\n }\n\n return returnTypeString;\n}\n\nfunction stringifyTSObjectArg(arg: any) {\n let ret = \"unknown\";\n let isNullable = true;\n\n if (arg instanceof GraphQLNonNull) {\n isNullable = false;\n arg = arg.ofType;\n }\n\n if (\n arg instanceof GraphQLInputObjectType ||\n arg instanceof GraphQLScalarType\n ) {\n ret = arg.name;\n }\n\n if (isNullable) {\n ret += \" | null | undefined\"; // we also want undefined in args\n }\n\n return ret;\n}\n\nfunction mapGraphqlScalarToTSTypeString(arg: any) {\n switch (arg.name) {\n case \"ID\":\n return \"string\";\n case \"String\":\n return \"string\";\n case \"Boolean\":\n return \"boolean\";\n case \"Int\":\n return \"number\";\n case \"Float\":\n return \"number\";\n case \"Date\":\n return \"Date\";\n case \"DateTime\":\n return \"Date\";\n case \"JSON\":\n return \"any\";\n default:\n return \"unknown\";\n }\n}\n\nfunction makeStringLiteralUnionFromEnum(enumType: GraphQLEnumType) {\n return enumType\n .getValues()\n .map((value) => `\"${value.name}\"`)\n .join(\" | \");\n}\n","import { access, mkdir, rm, writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport {\n getIntrospectedSchema,\n minifyIntrospectionQuery,\n} from \"@urql/introspection\";\nimport { uneval } from \"devalue\";\nimport type { GraphQLSchema } from \"graphql\";\nimport { generateClient } from \"./client\";\nimport { makeTSRepresentation } from \"./tsRepresentation\";\n\nexport async function generateFromSchema({\n outputPath,\n schema,\n rumbleImportPath = \"@m1212e/rumble/client\",\n apiUrl,\n useExternalUrqlClient = false,\n removeExisting = true,\n forceReactivity,\n}: {\n schema: GraphQLSchema;\n outputPath: string;\n rumbleImportPath?: string;\n apiUrl?: string;\n useExternalUrqlClient?: boolean | string;\n removeExisting?: boolean;\n forceReactivity?: boolean;\n}) {\n if (removeExisting) {\n try {\n await access(outputPath);\n await rm(outputPath, { recursive: true, force: true });\n } catch (_error) {}\n }\n\n await mkdir(outputPath, { recursive: true });\n\n if (!outputPath.endsWith(\"/\")) {\n outputPath += \"/\";\n }\n\n const imports: string[] = [];\n let code = \"\";\n\n const typeMap = new Map<string, any>();\n for (const [key, object] of Object.entries(schema.getTypeMap())) {\n if (key.startsWith(\"__\")) continue;\n typeMap.set(key, object);\n }\n\n for (const [key, object] of typeMap.entries()) {\n const rep = makeTSRepresentation(object);\n\n if (rep === key) {\n continue;\n }\n\n code += `\nexport type ${key} = ${rep};\n\t\t`;\n }\n\n const schemaFileName = \"schema\";\n\n const c = generateClient({\n apiUrl,\n schemaPath: `./${schemaFileName}`,\n useExternalUrqlClient,\n rumbleImportPath,\n availableSubscriptions: new Set(\n Object.keys(schema.getSubscriptionType()?.getFields() || {}),\n ),\n forceReactivity,\n });\n\n imports.push(...c.imports);\n code += c.code;\n\n await Promise.all([\n writeFile(join(outputPath, \"client.ts\"), `${imports.join(\"\\n\")}\\n${code}`),\n writeFile(\n join(outputPath, `${schemaFileName}.ts`),\n `\nimport type { IntrospectionQuery } from \"graphql\";\nexport const schema = ${uneval(minifyIntrospectionQuery(getIntrospectedSchema(schema), { includeEnums: true, includeScalars: true, includeInputs: true }))} as IntrospectionQuery`,\n ),\n ]);\n}\n"],"mappings":";;;;;;;AAAA,SAAgB,eAAe,EAC7B,QACA,kBACA,uBACA,wBACA,YACA,mBAQC;CACD,MAAMA,UAAoB,EAAE;CAC5B,IAAIC,OAAe;AAEnB,KAAI,OAAO,0BAA0B,SACnC,SAAQ,KAAK,+BAA+B,sBAAsB,IAAI;AAGxE,SAAQ,KAAK,sDAAsD;AACnE,SAAQ,KAAK,6DAA6D;AAC1E,SAAQ,KAAK,uCAAuC,iBAAiB,IAAI;AACzE,SAAQ,KAAK,2BAA2B,WAAW,IAAI;AAEvD,SAAQ,KACN,6EAA6E,iBAAiB,IAC/F;CAED,MAAM,6BACJ,OAAO,oBAAoB,aAAa,kBACpC,gCACA;CACN,MAAM,4BACJ,OAAO,oBAAoB,aAAa,kBAAkB,WAAW;AAEvE,SAAQ;;UAEA,UAAU,yEAAyE;;;;;;;;;AAU3F,KAAI,CAAC,sBACH,SAAQ;;;AAKV,SAAQ;;;;;;;;;;kCAUwB,0BAA0B;;sCAEtB,uBAC/B,QAAQ,CACR,SAAS,CACT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D;EACD;EACD,CAAC;AAEF,SAAQ,KAAK,GAAG,EAAE,QAAQ;AAC1B,SAAQ,EAAE;AAEV,OAAM,QAAQ,IAAI,CAChB,UAAU,KAAK,YAAY,YAAY,EAAE,GAAG,QAAQ,KAAK,KAAK,CAAC,IAAI,OAAO,EAC1E,UACE,KAAK,YAAY,GAAG,eAAe,KAAK,EACxC;;wBAEkB,OAAO,yBAAyB,sBAAsB,OAAO,EAAE;EAAE,cAAc;EAAM,gBAAgB;EAAM,eAAe;EAAM,CAAC,CAAC,CAAC,wBACtJ,CACF,CAAC"}
|
package/out/index.cjs
CHANGED
|
@@ -6,12 +6,16 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
15
19
|
}
|
|
16
20
|
return to;
|
|
17
21
|
};
|
|
@@ -21,10 +25,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
25
|
}) : target, mod));
|
|
22
26
|
|
|
23
27
|
//#endregion
|
|
24
|
-
const
|
|
28
|
+
const require_lazy = require('./lazy-BrDkNRyV.cjs');
|
|
29
|
+
const require_generate = require('./generate-9zSO5f7n.cjs');
|
|
25
30
|
let graphql = require("graphql");
|
|
26
|
-
let
|
|
27
|
-
let
|
|
31
|
+
let _escape_tech_graphql_armor = require("@escape.tech/graphql-armor");
|
|
32
|
+
let _graphql_yoga_plugin_disable_introspection = require("@graphql-yoga/plugin-disable-introspection");
|
|
28
33
|
let es_toolkit = require("es-toolkit");
|
|
29
34
|
let graphql_yoga = require("graphql-yoga");
|
|
30
35
|
let sofa_api = require("sofa-api");
|
|
@@ -35,12 +40,12 @@ let pluralize = require("pluralize");
|
|
|
35
40
|
pluralize = __toESM(pluralize);
|
|
36
41
|
let drizzle_orm_mysql_core = require("drizzle-orm/mysql-core");
|
|
37
42
|
let drizzle_orm_sqlite_core = require("drizzle-orm/sqlite-core");
|
|
38
|
-
let
|
|
39
|
-
|
|
40
|
-
let
|
|
41
|
-
|
|
42
|
-
let
|
|
43
|
-
|
|
43
|
+
let _pothos_core = require("@pothos/core");
|
|
44
|
+
_pothos_core = __toESM(_pothos_core);
|
|
45
|
+
let _pothos_plugin_drizzle = require("@pothos/plugin-drizzle");
|
|
46
|
+
_pothos_plugin_drizzle = __toESM(_pothos_plugin_drizzle);
|
|
47
|
+
let _pothos_plugin_smart_subscriptions = require("@pothos/plugin-smart-subscriptions");
|
|
48
|
+
_pothos_plugin_smart_subscriptions = __toESM(_pothos_plugin_smart_subscriptions);
|
|
44
49
|
let graphql_scalars = require("graphql-scalars");
|
|
45
50
|
|
|
46
51
|
//#region lib/types/rumbleError.ts
|
|
@@ -64,14 +69,14 @@ var RumbleErrorSafe = class extends graphql.GraphQLError {};
|
|
|
64
69
|
//#endregion
|
|
65
70
|
//#region lib/helpers/asserts.ts
|
|
66
71
|
/**
|
|
67
|
-
*
|
|
72
|
+
*
|
|
68
73
|
* Helper function to map a drizzle findFirst query result,
|
|
69
74
|
* which may be optional, to a correct drizzle type.
|
|
70
|
-
*
|
|
75
|
+
*
|
|
71
76
|
* @throws RumbleError
|
|
72
|
-
*
|
|
77
|
+
*
|
|
73
78
|
* @example
|
|
74
|
-
*
|
|
79
|
+
*
|
|
75
80
|
* ```ts
|
|
76
81
|
* schemaBuilder.queryFields((t) => {
|
|
77
82
|
return {
|
|
@@ -98,14 +103,14 @@ const assertFindFirstExists = (value) => {
|
|
|
98
103
|
return value;
|
|
99
104
|
};
|
|
100
105
|
/**
|
|
101
|
-
*
|
|
106
|
+
*
|
|
102
107
|
* Helper function to map a drizzle findFirst query result,
|
|
103
108
|
* which may be optional, to a correct drizzle type.
|
|
104
|
-
*
|
|
109
|
+
*
|
|
105
110
|
* @throws RumbleError
|
|
106
|
-
*
|
|
111
|
+
*
|
|
107
112
|
* @example
|
|
108
|
-
*
|
|
113
|
+
*
|
|
109
114
|
* ```ts
|
|
110
115
|
schemaBuilder.mutationFields((t) => {
|
|
111
116
|
return {
|
|
@@ -206,30 +211,6 @@ function mapNullFieldsToUndefined(obj) {
|
|
|
206
211
|
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, value === null ? void 0 : value]));
|
|
207
212
|
}
|
|
208
213
|
|
|
209
|
-
//#endregion
|
|
210
|
-
//#region lib/helpers/lazy.ts
|
|
211
|
-
/**
|
|
212
|
-
* Creates a lazily initialized function.
|
|
213
|
-
*
|
|
214
|
-
* The returned function will call the initializer function on its first call and
|
|
215
|
-
* store the result. On subsequent calls, it will return the stored result.
|
|
216
|
-
*
|
|
217
|
-
* @param initializer The function to be called for initialization.
|
|
218
|
-
* @returns A function that calls the initializer function on its first call and
|
|
219
|
-
* returns the stored result on subsequent calls.
|
|
220
|
-
*/
|
|
221
|
-
function lazy(initializer) {
|
|
222
|
-
let value;
|
|
223
|
-
let initialized = false;
|
|
224
|
-
return () => {
|
|
225
|
-
if (!initialized) {
|
|
226
|
-
value = initializer();
|
|
227
|
-
initialized = true;
|
|
228
|
-
}
|
|
229
|
-
return value;
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
|
|
233
214
|
//#endregion
|
|
234
215
|
//#region lib/helpers/mergeFilters.ts
|
|
235
216
|
function mergeFilters(filterA, filterB) {
|
|
@@ -461,7 +442,7 @@ const createAbilityBuilder = ({ db, actions, defaultLimit }) => {
|
|
|
461
442
|
*/
|
|
462
443
|
function transformToResponse(queryFilters$1) {
|
|
463
444
|
const internalTransformer = (filters, mergedLimit) => {
|
|
464
|
-
const limit = lazy(() => {
|
|
445
|
+
const limit = require_lazy.lazy(() => {
|
|
465
446
|
if (mergedLimit !== void 0) {
|
|
466
447
|
if (!filters?.limit) return mergedLimit;
|
|
467
448
|
if (filters.limit > mergedLimit) return mergedLimit;
|
|
@@ -470,7 +451,7 @@ const createAbilityBuilder = ({ db, actions, defaultLimit }) => {
|
|
|
470
451
|
if (defaultLimit && (limit$1 === void 0 || limit$1 > defaultLimit)) limit$1 = defaultLimit;
|
|
471
452
|
return limit$1 ?? void 0;
|
|
472
453
|
});
|
|
473
|
-
const sqlTransformedWhere = lazy(() => {
|
|
454
|
+
const sqlTransformedWhere = require_lazy.lazy(() => {
|
|
474
455
|
return filters?.where ? (0, drizzle_orm.relationsFilterToSQL)(tableSchema.foundRelation.table, filters.where) : void 0;
|
|
475
456
|
});
|
|
476
457
|
if (filters?.columns) return {
|
|
@@ -563,7 +544,7 @@ const createAbilityBuilder = ({ db, actions, defaultLimit }) => {
|
|
|
563
544
|
const makeDefaultName$1 = (dbName) => `${(0, es_toolkit.capitalize)((0, drizzle_orm_casing.toCamelCase)(dbName.toString()))}OrderInputArgument`;
|
|
564
545
|
const createOrderArgImplementer = ({ db, schemaBuilder }) => {
|
|
565
546
|
const referenceStorage = /* @__PURE__ */ new Map();
|
|
566
|
-
const sortingParameterEnumRef = lazy(() => schemaBuilder.enumType("SortingParameter", { values: ["asc", "desc"] }));
|
|
547
|
+
const sortingParameterEnumRef = require_lazy.lazy(() => schemaBuilder.enumType("SortingParameter", { values: ["asc", "desc"] }));
|
|
567
548
|
const orderArgImplementer = ({ table, refName, dbName }) => {
|
|
568
549
|
const tableSchema = tableHelper({
|
|
569
550
|
db,
|
|
@@ -733,7 +714,13 @@ const createWhereArgImplementer = ({ db, schemaBuilder, enumImplementer }) => {
|
|
|
733
714
|
//#region lib/client/client.ts
|
|
734
715
|
const clientCreatorImplementer = ({ builtSchema }) => {
|
|
735
716
|
const clientCreator = async ({ apiUrl, outputPath, rumbleImportPath, useExternalUrqlClient, removeExisting, forceReactivity }) => {
|
|
736
|
-
if (process.env.NODE_ENV !== "development") console.warn(
|
|
717
|
+
if (process.env.NODE_ENV !== "development") console.warn(`Running rumble client generation in non development mode. Are you sure this is correct? Called from ${__filename} with arguments: ${JSON.stringify({
|
|
718
|
+
outputPath,
|
|
719
|
+
apiUrl,
|
|
720
|
+
rumbleImportPath,
|
|
721
|
+
useExternalUrqlClient,
|
|
722
|
+
removeExisting
|
|
723
|
+
})}`);
|
|
737
724
|
await require_generate.generateFromSchema({
|
|
738
725
|
schema: builtSchema(),
|
|
739
726
|
outputPath,
|
|
@@ -750,7 +737,7 @@ const clientCreatorImplementer = ({ builtSchema }) => {
|
|
|
750
737
|
//#endregion
|
|
751
738
|
//#region lib/context.ts
|
|
752
739
|
const createContextFunction = ({ context: makeUserContext, abilityBuilder }) => {
|
|
753
|
-
const builtAbilityBuilder = lazy(() => abilityBuilder._.build());
|
|
740
|
+
const builtAbilityBuilder = require_lazy.lazy(() => abilityBuilder._.build());
|
|
754
741
|
return async (req) => {
|
|
755
742
|
const userContext = makeUserContext ? await makeUserContext(req) : {};
|
|
756
743
|
return {
|
|
@@ -1035,7 +1022,7 @@ const createObjectImplementer = ({ db, search, schemaBuilder, makePubSubInstance
|
|
|
1035
1022
|
fields: (t) => {
|
|
1036
1023
|
const columns = tableSchema.columns;
|
|
1037
1024
|
const configMap = /* @__PURE__ */ new Map();
|
|
1038
|
-
const userAdjustments = adjust?.(new Proxy(t, { get: (target, prop) => {
|
|
1025
|
+
const userAdjustments = adjust?.(new Proxy(t, { get: (target, prop, receiver) => {
|
|
1039
1026
|
if (typeof target[prop] !== "function" || prop === "arg" || prop === "builder" || prop === "graphqlKind" || prop === "kind" || prop === "listRef" || prop === "table" || prop === "typename" || prop === "variant" || prop.toString().startsWith("boolean") || prop.toString().startsWith("float") || prop.toString().startsWith("id") || prop.toString().startsWith("int") || prop.toString().startsWith("string") || prop.toString().startsWith("expose")) return target[prop];
|
|
1040
1027
|
return (...params) => {
|
|
1041
1028
|
const ref = target[prop](...params);
|
|
@@ -1433,7 +1420,7 @@ const applyFilters = async ({ filters, entities, context }) => {
|
|
|
1433
1420
|
//#endregion
|
|
1434
1421
|
//#region lib/runtimeFiltersPlugin/runtimeFiltersPlugin.ts
|
|
1435
1422
|
const applyFiltersKey = "applyFilters";
|
|
1436
|
-
var RuntimeFiltersPlugin = class extends
|
|
1423
|
+
var RuntimeFiltersPlugin = class extends _pothos_core.BasePlugin {
|
|
1437
1424
|
wrapResolve(resolver, fieldConfig) {
|
|
1438
1425
|
return async (parent, args, context, info) => {
|
|
1439
1426
|
let filters;
|
|
@@ -1456,7 +1443,7 @@ var RuntimeFiltersPlugin = class extends __pothos_core.BasePlugin {
|
|
|
1456
1443
|
let registered = false;
|
|
1457
1444
|
function registerRuntimeFiltersPlugin() {
|
|
1458
1445
|
if (!registered) {
|
|
1459
|
-
|
|
1446
|
+
_pothos_core.default.registerPlugin(pluginName, RuntimeFiltersPlugin);
|
|
1460
1447
|
registered = true;
|
|
1461
1448
|
}
|
|
1462
1449
|
}
|
|
@@ -1465,12 +1452,12 @@ function registerRuntimeFiltersPlugin() {
|
|
|
1465
1452
|
//#region lib/schemaBuilder.ts
|
|
1466
1453
|
const createSchemaBuilder = ({ db, disableDefaultObjects, pubsub, pothosConfig }) => {
|
|
1467
1454
|
registerRuntimeFiltersPlugin();
|
|
1468
|
-
const schemaBuilder = new
|
|
1455
|
+
const schemaBuilder = new _pothos_core.default({
|
|
1469
1456
|
...pothosConfig,
|
|
1470
1457
|
plugins: [
|
|
1471
1458
|
pluginName,
|
|
1472
|
-
|
|
1473
|
-
|
|
1459
|
+
_pothos_plugin_drizzle.default,
|
|
1460
|
+
_pothos_plugin_smart_subscriptions.default,
|
|
1474
1461
|
...pothosConfig?.plugins ?? []
|
|
1475
1462
|
],
|
|
1476
1463
|
drizzle: {
|
|
@@ -1483,7 +1470,7 @@ const createSchemaBuilder = ({ db, disableDefaultObjects, pubsub, pothosConfig }
|
|
|
1483
1470
|
};
|
|
1484
1471
|
}
|
|
1485
1472
|
},
|
|
1486
|
-
smartSubscriptions: { ...(0,
|
|
1473
|
+
smartSubscriptions: { ...(0, _pothos_plugin_smart_subscriptions.subscribeOptionsFromIterator)((name, _context) => {
|
|
1487
1474
|
return pubsub.subscribe(name);
|
|
1488
1475
|
}) },
|
|
1489
1476
|
defaultFieldNullability: false
|
|
@@ -1579,13 +1566,13 @@ export const db = drizzle(
|
|
|
1579
1566
|
whereArgImplementer: whereArg,
|
|
1580
1567
|
makePubSubInstance
|
|
1581
1568
|
});
|
|
1582
|
-
const builtSchema = lazy(() => schemaBuilder.toSchema());
|
|
1569
|
+
const builtSchema = require_lazy.lazy(() => schemaBuilder.toSchema());
|
|
1583
1570
|
const createYoga = (args) => {
|
|
1584
1571
|
const enableApiDocs = args?.enableApiDocs ?? process?.env?.NODE_ENV === "development";
|
|
1585
1572
|
return (0, graphql_yoga.createYoga)({
|
|
1586
1573
|
...args,
|
|
1587
1574
|
graphiql: enableApiDocs,
|
|
1588
|
-
plugins: [...args?.plugins ?? [], ...enableApiDocs ? [] : [(0,
|
|
1575
|
+
plugins: [...args?.plugins ?? [], ...enableApiDocs ? [] : [(0, _graphql_yoga_plugin_disable_introspection.useDisableIntrospection)(), (0, _escape_tech_graphql_armor.EnvelopArmorPlugin)()]].filter(Boolean),
|
|
1589
1576
|
schema: builtSchema(),
|
|
1590
1577
|
context
|
|
1591
1578
|
});
|