diff --git a/src/framework/database/helpers/paginate.ts b/src/framework/database/helpers/paginate.ts index 5c7a8adc..bf023631 100644 --- a/src/framework/database/helpers/paginate.ts +++ b/src/framework/database/helpers/paginate.ts @@ -9,7 +9,7 @@ export default async function (model) { throw new Error("Requested fields must be an array") } let page = get(args, "pagination.page", 1) - let limit = get(args, "pagination.limit", 500) + let limit = get(args, "pagination.limit", 100) let filters = get(args, "filters", {}) let sorting = get(args, "sorting", []) let offset = limit * (page - 1) @@ -53,6 +53,7 @@ export default async function (model) { previousPage: page == 1 ? 1 : page - 1, pages: totalPages, hasMore: page < totalPages, + limit: limit, }, }) } catch (error) { 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/crud/index.ts b/src/next/crud/index.ts index 677ac994..74867dd5 100644 --- a/src/next/crud/index.ts +++ b/src/next/crud/index.ts @@ -3,7 +3,7 @@ import convertFiltersIntoSequalizeObject from "./../../framework/database/helper export const paginate = async (arg, tableInstance) => { let page = get(arg, "pagination.page", 1) - let limit = get(arg, "pagination.limit", 500) + let limit = get(arg, "pagination.limit", 100) let sorting = get(arg, "sorting", []) let offset = limit * (page - 1) const where = await convertFiltersIntoSequalizeObject(arg.where) @@ -25,6 +25,7 @@ export const paginate = async (arg, tableInstance) => { previousPage: page == 1 ? 1 : page - 1, pages: totalPages, hasMore: page < totalPages, + limit: limit }, } } 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/graphql/generalSchema.ts b/src/next/graphql/generalSchema.ts index 70c3b28e..eee9866d 100644 --- a/src/next/graphql/generalSchema.ts +++ b/src/next/graphql/generalSchema.ts @@ -86,5 +86,6 @@ export default ` nextPage: Int previousPage: Int hasMore: Boolean + limit: Int } ` 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 } }