From 3a1c30f5661b977283542190d78e23c9d1ccf21a Mon Sep 17 00:00:00 2001 From: ilyas Date: Wed, 26 Jan 2022 02:17:48 +0500 Subject: [PATCH] Hot Fixes --- src/framework/graphql/generalSchema.ts | 1 + src/next/database.ts | 4 ++-- src/next/devServers/dev-ilyas.ts | 18 ++++++++++++++++++ src/next/index.ts | 6 +++--- src/next/types/modules.ts | 2 +- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/framework/graphql/generalSchema.ts b/src/framework/graphql/generalSchema.ts index 830ba208..514c5a74 100644 --- a/src/framework/graphql/generalSchema.ts +++ b/src/framework/graphql/generalSchema.ts @@ -81,5 +81,6 @@ export default ` nextPage: Int previousPage: Int hasMore: Boolean + limit: Int } ` diff --git a/src/next/database.ts b/src/next/database.ts index 5b253cbf..ff9e35d5 100644 --- a/src/next/database.ts +++ b/src/next/database.ts @@ -52,7 +52,7 @@ export const applyRelationshipsFromStoreToDatabase = async ( store.database.relationships.forEach((element) => { const currentTable = app.modules[element.currentModule].tableInstance const referencedTable = app.modules[element.referencedModule].tableInstance - // element.type willbe hasOne, hasMany, belongsTo or belongsToMany + // element.type will be hasOne, hasMany, belongsTo or belongsToMany currentTable[element.type](referencedTable, element.options || {}) }) } @@ -70,7 +70,7 @@ export const applyRelationshipsFromStoreToGraphql = async ( store.graphql.resolvers[element.currentModule] = { ...oldResolvers, - [element.graphqlKey]: async (parent, args, context) => { + [element.graphqlKey]: async (parent, _args, context) => { const tableInstance = context.wertik.modules[element.referencedModule].tableInstance let referencedModuleKey = diff --git a/src/next/devServers/dev-ilyas.ts b/src/next/devServers/dev-ilyas.ts index f895db3a..9e731537 100644 --- a/src/next/devServers/dev-ilyas.ts +++ b/src/next/devServers/dev-ilyas.ts @@ -28,6 +28,24 @@ const devIlyas = async () => { database: "default", table: "shirts", }), + shirt_sales: useModule({ + name: "shirt_sales", + useDatabase: true, + database: "default", + table: "shirt_sales", + on: ({ hasOne }) => { + hasOne({ + module: "shirts", + graphqlKey: "shirt", + database: "default", + options: { + foreignKey: "id", + sourceKey: "shirt_id", + targetKey: "shirt_id", + }, + }) + }, + }), }, }) } diff --git a/src/next/index.ts b/src/next/index.ts index f9fe15c4..0b91f97c 100644 --- a/src/next/index.ts +++ b/src/next/index.ts @@ -95,9 +95,6 @@ const Wertik: (configuration: WertikConfiguration) => Promise = ( } } - applyRelationshipsFromStoreToDatabase(store, wertikApp) - applyRelationshipsFromStoreToGraphql(store, wertikApp) - if (configuration.modules) { for (const moduleName of Object.keys(configuration.modules || {})) { wertikApp.modules[moduleName] = await configuration.modules[ @@ -133,6 +130,9 @@ const Wertik: (configuration: WertikConfiguration) => Promise = ( } } + applyRelationshipsFromStoreToDatabase(store, wertikApp) + applyRelationshipsFromStoreToGraphql(store, wertikApp) + expressApp.get("/w/info", function (req, res) { res.json({ message: "You are running wertik-js v3", diff --git a/src/next/types/modules.ts b/src/next/types/modules.ts index 7e405464..e800c2fa 100644 --- a/src/next/types/modules.ts +++ b/src/next/types/modules.ts @@ -33,7 +33,7 @@ export interface RelationParams { module: string graphqlKey: string database: string - options: { + options?: { [key: string]: string | number | null } }