Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyaskarim committed Jan 25, 2022
2 parents cc756a0 + d138137 commit 7655c63
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/framework/database/helpers/paginate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -53,6 +53,7 @@ export default async function (model) {
previousPage: page == 1 ? 1 : page - 1,
pages: totalPages,
hasMore: page < totalPages,
limit: limit,
},
})
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions src/framework/graphql/generalSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,6 @@ export default `
nextPage: Int
previousPage: Int
hasMore: Boolean
limit: Int
}
`
3 changes: 2 additions & 1 deletion src/next/crud/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -25,6 +25,7 @@ export const paginate = async (arg, tableInstance) => {
previousPage: page == 1 ? 1 : page - 1,
pages: totalPages,
hasMore: page < totalPages,
limit: limit
},
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/next/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {})
})
}
Expand All @@ -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 =
Expand Down
18 changes: 18 additions & 0 deletions src/next/devServers/dev-ilyas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
})
},
}),
},
})
}
Expand Down
1 change: 1 addition & 0 deletions src/next/graphql/generalSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@ export default `
nextPage: Int
previousPage: Int
hasMore: Boolean
limit: Int
}
`
6 changes: 3 additions & 3 deletions src/next/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,6 @@ const Wertik: (configuration: WertikConfiguration) => Promise<WertikApp> = (
}
}

applyRelationshipsFromStoreToDatabase(store, wertikApp)
applyRelationshipsFromStoreToGraphql(store, wertikApp)

if (configuration.modules) {
for (const moduleName of Object.keys(configuration.modules || {})) {
wertikApp.modules[moduleName] = await configuration.modules[
Expand Down Expand Up @@ -133,6 +130,9 @@ const Wertik: (configuration: WertikConfiguration) => Promise<WertikApp> = (
}
}

applyRelationshipsFromStoreToDatabase(store, wertikApp)
applyRelationshipsFromStoreToGraphql(store, wertikApp)

expressApp.get("/w/info", function (req, res) {
res.json({
message: "You are running wertik-js v3",
Expand Down
2 changes: 1 addition & 1 deletion src/next/types/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface RelationParams {
module: string
graphqlKey: string
database: string
options: {
options?: {
[key: string]: string | number | null
}
}
Expand Down

0 comments on commit 7655c63

Please sign in to comment.