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

Eager loading of relations whlie using filters(v3.4) #346

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
8c5d119
in progress support for filtering with assosications sequelize
ilyaskarim Feb 11, 2023
f3b1e13
Replace pagination proerties with just pagination
ilyaskarim Feb 20, 2023
49c3617
Added eager loading to list query
ilyaskarim Feb 21, 2023
7383bda
Added eager loading for view query
ilyaskarim Feb 23, 2023
7f7ce0f
WIP: Eager loading
ilyaskarim Feb 24, 2023
a2a845d
Fixed associations eager loading issue and added logs for when regist…
ilyaskarim Feb 25, 2023
d46ee99
Finished eager loading
ilyaskarim Feb 25, 2023
0695558
Prettier
ilyaskarim Feb 25, 2023
2d97b5f
Added recursion attributes, filters to eager loading graphql queries
ilyaskarim Feb 26, 2023
de9687d
Run prettier
ilyaskarim Feb 26, 2023
e0b48ab
Added prettier to commit
ilyaskarim Feb 27, 2023
14cee70
Change in test and logs in database.ts file
ilyaskarim Feb 27, 2023
bea149e
Changed messages
ilyaskarim Feb 27, 2023
bcd0781
Fixed imports in crud/index.ts
ilyaskarim Feb 27, 2023
3ac3bde
Changing label messages in terminal when starting servers
ilyaskarim Feb 27, 2023
b916240
crud graphql
ilyaskarim Mar 3, 2023
9006e80
eager loading mysql query
ilyaskarim Apr 18, 2023
2278cff
remove husky
ilyaskarim Apr 18, 2023
77d3803
added 3.4.0 change log
ilyaskarim Apr 18, 2023
f253fa5
Fix grammar mistakes in Changelog, tested 3.4.0 updates
ilyaskarim Jul 1, 2023
9914938
Update changelog.md
ilyaskarim Jul 1, 2023
6bab145
'[Build Optimization] Removed lodash, installed its child packages to…
ilyaskarim Jul 1, 2023
81e5f12
Fix sonar issues, and reduced code smells to less than 10
ilyaskarim Jul 1, 2023
3735e26
Types renaming and fixing typos
ilyaskarim Jul 23, 2023
4e75e60
Added startServer(), restartServer(), stopServer() methods
ilyaskarim Jul 23, 2023
cbfca0d
Allow restart server to just restart server not the new configuration
ilyaskarim Jul 23, 2023
bbe8333
Added test database
ilyaskarim Jul 23, 2023
6e091cd
v3.4 added tests to ensure graphql operations work perfectly.
ilyaskarim Jul 29, 2023
456c869
Update changelog.md
ilyaskarim Jul 29, 2023
2af5667
v3.4 Removed where from hasOne and belongsTo query because using filt…
ilyaskarim Jul 30, 2023
081dd35
v3.4 reset required fix
ilyaskarim Jul 30, 2023
068db16
Todo comment remove fix
ilyaskarim Jul 30, 2023
ce35b40
Todo comment remove fix
ilyaskarim Jul 30, 2023
da7840f
v3.4 updates
ilyaskarim Sep 28, 2023
8c3fe49
Converted graphql types to camel case
ilyaskarim Sep 28, 2023
dc06030
Updated change log
ilyaskarim Sep 28, 2023
94b4d1c
v3.4 added more test and replaced rows with list in function convertG…
ilyaskarim Nov 10, 2023
e83c82e
Update changelog.md
ilyaskarim Jan 2, 2024
558e6a4
Finalizing 3.4
ilyaskarim Jan 2, 2024
0bfed49
Fixed isNull not working properly
ilyaskarim Jan 3, 2024
64e7d56
refactor: run prettier
ilyaskarim Jan 3, 2024
d012b23
v3.4 Change configuration prop `skip` to `selfStart` to make it more…
ilyaskarim Apr 7, 2024
60264c8
v3.4 renaming stuff from use to with
ilyaskarim Apr 7, 2024
1be79a3
V3.4 Fetch graphql keys in convertGraphqlRequestedFieldsIntoInclude a…
ilyaskarim Apr 9, 2024
b18783c
v3.4 replace sorting with order and allow deep sorting
ilyaskarim Apr 10, 2024
16e17dd
v3.4 Added sorting for deep level
ilyaskarim Apr 13, 2024
6f5ed59
v3.4 fix tests and finalize order
ilyaskarim Apr 13, 2024
e9563b1
Remove test-database-folder
ilyaskarim Apr 13, 2024
8d77d53
Tables in database initial work
ilyaskarim Apr 14, 2024
9425106
Add initial schema from tables in database and change location of sto…
ilyaskarim Apr 14, 2024
f6fe2e5
v3.4 tables in database almost done
ilyaskarim Apr 14, 2024
33b88d9
Update modules.ts
ilyaskarim May 12, 2024
1dbd5a1
Merge pull request #347 from Uconnect-Technologies/v3.4-tables-in-dat…
ilyaskarim May 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ warning.log
.env
/backups
.DS_STORE
lib
lib

.scannerwork
graphqlSchema.graphql
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ warning.log
uploads
backups
docs
tests
tests

test_database.sql
File renamed without changes.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"Wertik"
]
}
41 changes: 38 additions & 3 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,49 @@
## Started changelog after version 3.2.9

### 3.4.0

- Added eager loading for list and view queries.
- Improved lazy loading behavior in GraphQL to avoid unnecessary queries.
- Added support for loading only requested fields in Sequelize.
- Added recursion support for both list and view queries.
- Added support for filtering associated data in recursive queries.
- Replaced moment.js with dayjs.
- Scanned and verified fixes with SonarQube.
- Removed lodash and installed its child packages to reduce app size.
- Added methods: `startServer()`, `restartServer()`, `stopServer()`.
- Removed query `list`. For example for Module `Users`, `listUsers` will become `users`, `EcommerceUsers` will become `ecommerce_users`.
- From single query item `view` is removed, For example `viewUser` will become `user` and `EcommerceUser` will become `ecommerce_user`
- Changed GraphQL list field from `list` to `rows`.
- Removed `applyRelationshipsFromStoreToGraphql` method due to the shift towards eager loading.
- Appended `Module` after module names in GraphQL types, e.g., `User` is now `UserModule`.
- Added tests to ensure GraphQL operations function correctly.
- Introduced an option to output GraphQL type definitions in a file.
- Change configuration prop `skip` to `selfStart` to make it more intuitive.
- Rename `useMysqlDatabase` to `withMysqlDatabase` with its props.
- Rename `useRedis` to `withRedis` with its props.
- Rename `useGraphql` to `withGraphql` with its props.
- Rename `useMailer` to `withMailer` with its props.
- Rename `useSocketIO` to `withSocketIO` with its props.
- Rename `useWebSockets` to `withWebSockets` with its props.
- Rename `useIndependentWebSocketsServer` to `withIndependentWebSocketsServer` with its props.
- Rename `useLogger` to `withLogger` with its props.
- Rename `useWinstonTransport` to `withWinstonTransport` with its props.
- Rename `useQueue` to `withQueue` with its props.
- Verified tests with Jest for renaming changes.
- Rename `useSchema` to `extendSchema` with its props.
- Rename `useMutation` to `addMutation` with its props.
- Rename `useExpress` to `getExpress`.
- BREAKING CHANGE: Remove `useModule` and allowed using tables on database configuration.

### 3.3.0

- When sending emails fails, also throws errors in console
- When taking backup and provides invalid table/module name, the backup process failes with an error.
- When taking backup and provides invalid table/module name, the backup process failed with an error.
- Added `extendFields` to `useModule` to extend `sequelize.model` table fields.

### 3.3.1

- Removed support old legacy wertik framework.
- Removed old legacy wertik framework.
- Now wertik can be import from `wertik-js/lib` instead of `wertik-js/lib/ndex`
- Added more types support.
- Change the way mysql is initalized so that it can open doors for postgres and mongoose in future.
- Change the way mysql is initialized so that it can open doors for postgres and mongoose in future.
14 changes: 7 additions & 7 deletions docs/v3/graphql.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
# GraphQL

For GraphQL, Wertik JS uses Apollo GraphQL under the hood. We choose Apollo GraphQL because it is well managed and bug-free. To set up Graphql Wertik JS provides a function called `useGraphql` to use Graphql in your app.
For GraphQL, Wertik JS uses Apollo GraphQL under the hood. We choose Apollo GraphQL because it is well managed and bug-free. To set up Graphql Wertik JS provides a function called `withGraphql` to use Graphql in your app.

```javascript
import wertik, { useGraphql } from "wertik-js/lib/";
import wertik, { withGraphql } from "wertik-js/lib/";
wertik({
port: 1200,
graphql: useGraphql(useGraphqlProps),
graphql: withGraphql(WithGraphqlProps),
});
```

This will initialize GraphQL on URL: http://localhost:1200/graphql. If you visit this link you will Apollo GraphQL playground.

#### useGraphqlProps
#### WithGraphqlProps

useGraphqlProps is an argument which is optional when using `useGraphql` method.
WithGraphqlProps is an argument which is optional when using `withGraphql` method.

```typescript
export interface useGraphqlProps {
export interface WithGraphqlProps {
options?: {
[key: string]: any;
};
Expand All @@ -32,5 +32,5 @@ export interface useGraphqlProps {

- options includes ApolloServer options.
- applyMiddlewareOptions includes options while integrating Apollo Server with express server with same port.
- resolvers for defined schema in useGraphqlProps.typeDefs.
- resolvers for defined schema in WithGraphqlProps.typeDefs.
- typeDefs is your graphql schema.
52 changes: 26 additions & 26 deletions docs/v3/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ Wertik-js allows extending your app with more features using the `modules` term.

```js
import wertik, {
useMysqlDatabase,
useMailer,
useModule,
useGraphql,
withMysqlDatabase,
withMailer,
withModule,
withGraphql,
} from "wertik-js/lib/";

weritk({
port: 1200,
database: {
default: useMysqlDatabase({
default: withMysqlDatabase({
name: "default",
password: "pass",
host: "localhost",
port: 3306,
username: "root",
}),
},
graphql: useGraphql(),
graphql: withGraphql,(),
mailer: {
default: useMailer(),
default: withMailer(),
},
modules: {
users: useModule({
users: withModule({
table: "users",
database: "default",
name: "users",
useMysqlDatabase: true,
useDatabase: true,
}),
},
});
Expand All @@ -48,10 +48,10 @@ When you provide `useMysqlDatabase: true`, `table` and `database`, Wertik JS aut
You have to initialize its module in this way:

```js
import wertik, { useModule, useMysqlDatabase, useGraphql } from "wertik-js/lib/";
import wertik, { useModule, useMysqlDatabase, withGraphql, } from "wertik-js/lib/";
wertik({
port: 1200,
graphql: useGraphql(),
graphql: withGraphql,(),
database: {
default: useMysqlDatabase({
name: "dbname",
Expand Down Expand Up @@ -98,13 +98,13 @@ input updateGamesInput {
For filtering data from `games` table, Wertik JS will also create an input for filtering:

```graphql
input GamesFilterInput {
name: StringFilterInput
publisher: StringFilterInput
input Gamesfilter_input {
name: Stringfilter_input
publisher: Stringfilter_input
}
```

To explore more about `StringFilterInput` and other filter input please visit GraphQL Playground to get more familiar with it.
To explore more about `Stringfilter_input` and other filter input please visit GraphQL Playground to get more familiar with it.

## This will generate

Expand All @@ -117,13 +117,13 @@ To explore more about `StringFilterInput` and other filter input please visit Gr
```graphql
type Query {
version: String
viewGames(where: GamesFilterInput): Games
viewGames(where: Gamesfilter_input): Games
listGames(
pagination: PaginationInput
where: GamesFilterInput
where: Gamesfilter_input
sorting: [SortingInput]
): GamesList
countGames(where: GamesFilterInput): Int
countGames(where: Gamesfilter_input): Int
}
```

Expand All @@ -140,10 +140,10 @@ type Mutation {
version: String
updateGames(
input: updateGamesInput
where: GamesFilterInput!
where: Gamesfilter_input!
): GamesBulkMutationResponse
createGames(input: [createGamesInput]): GamesBulkMutationResponse
deleteGames(where: GamesFilterInput!): SuccessResponse
deleteGames(where: Gamesfilter_input!): SuccessResponse
createOrUpdateGames(id: Int, input: createGamesInput): Games
}
```
Expand All @@ -157,7 +157,7 @@ When you provide `useMysqlDatabase: true` for a module called Games. Wertik JS w
```graphql
listGames(
pagination: PaginationInput
where: GamesFilterInput
where: Gamesfilter_input
sorting: [SortingInput]
): GamesList
```
Expand All @@ -171,7 +171,7 @@ input PaginationInput {
}
```

And `GamesFilterInput` is same as Sequelize search object but main keywords such as like, `eq` or `like` starts with `_`, For example:
And `Gamesfilter_input` is same as Sequelize search object but main keywords such as like, `eq` or `like` starts with `_`, For example:

```graphql
query GamesList {
Expand Down Expand Up @@ -280,25 +280,25 @@ wertik({
name: "Games",
table: "games",
database: "jscontainer",
on({ useExpress, useQuery, useMutation, useSchema }) {
on({ useExpress, addQuery, addMutation, extendSchema }) {
useExpress((express) => {
express.get("/404", (req, res) => res.status(404).send("404"));
});
useQuery({
addQuery({
name: "getGames",
query: "getGames: [Games]",
resolver() {
return [];
},
});
useMutation({
addMutation({
name: "updateAllGames",
query: "updateAllGames: [Games]",
resolver() {
return [];
},
});
useSchema(`
extendSchema(`
type MyType {
id: Int
name: String
Expand Down
4 changes: 2 additions & 2 deletions docs/v3/queue.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ This `useQueue` method simply instantiates a new instance of bull and returns th

- A queue can be instantiated with some useful options, for instance, we can specify the `location` and `password` of our Redis server, as well as some other useful settings. we can use them as `options : {redis : {port : 6379, host : "127.0.0.1", password : "somepass" }}`.

#### useQueueProps
#### UseQueueProps

-The `useQueue` method always expects an instantiation name such as(`my-queue-name`) all the other arguments are optional.

```typescript
export interface useQueueProps {
export interface UseQueueProps {
name?: string
url?: string
options?: QueueOptions
Expand Down
6 changes: 3 additions & 3 deletions docs/v3/redis.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Redis(Beta)

Wertik JS allows a using redis, Wertik JS uses package named `redis(options: useRedisProps)`. Wertik JS gives a function called `useRedis` which allows creating a redis server. Let's create a redis client:
Wertik JS allows a using redis, Wertik JS uses package named `redis(options: UseRedisProps)`. Wertik JS gives a function called `useRedis` which allows creating a redis server. Let's create a redis client:

Where `useRedisProps` is:
Where `UseRedisProps` is:

```typescript
export interface useRedisProps {
export interface UseRedisProps {
[key: string]: any
name: string;
}
Expand Down
20 changes: 14 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "wertik-js",
"version": "3.3.3",
"main": "lib/main.js",
"version": "3.4.0",
"main": "lib/index.js",
"types": "lib/types.d.ts",
"repository": "https://github.com/Uconnect-Technologies/wertik-js.git",
"keywords": [
Expand All @@ -26,9 +26,11 @@
"license": "MIT",
"scripts": {
"dev": "tsc-watch --onSuccess \"node lib/devServer.js\"",
"build": "yarn prettier && yarn tsc && yarn test",
"build": "rm -rf lib && yarn prettier && yarn tsc && yarn test",
"prettier": "prettier --write src package.json index.js",
"test": "cross-env TEST_MODE=true jest --runInBand --forceExit --detectOpenHandles"
"test": "cross-env TEST_MODE=true jest --runInBand --forceExit --detectOpenHandles",
"preinstall": "rm -rf node_modules",
"prepare": "yarn tsc"
},
"pre-commit": [
"prettier"
Expand All @@ -43,21 +45,27 @@
"chalk": "^3.0.0",
"cors": "^2.8.5",
"cross-env": "^7.0.3",
"dayjs": "^1.11.7",
"dropbox": "^8.2.0",
"express": "^4.17.1",
"graphql": "^15.7.2",
"graphql-depth-limit": "^1.1.0",
"graphql-fields": "^2.0.3",
"graphql-type-json": "^0.3.2",
"handlebars": "^4.5.3",
"lodash": "^4.17.15",
"lodash.get": "^4.4.2",
"lodash.has": "^4.5.2",
"lodash.isplainobject": "^4.0.6",
"lodash.omit": "^4.5.0",
"lodash.snakecase": "^4.1.1",
"log-symbols": "^3.0.0",
"moment": "^2.23.0",
"morgan": "^1.9.1",
"multer": "^1.4.2",
"mysql2": "^1.6.4",
"mysqldump": "^3.2.0",
"node-cron": "^2.0.3",
"nodemailer": ">=6.4.16",
"pluralize": "^8.0.0",
"redis": "^4.0.1",
"sequelize": "^6.3.5",
"socket.io": "^4.1.3",
Expand Down
6 changes: 3 additions & 3 deletions src/cronJobs/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { get } from "lodash"
import get from "lodash.get"
import nodeCron from "node-cron"
import { useCronJobsProps } from "../types/cronJobs"
import { UseCronJobsProps } from "../types/cronJobs"
import { iObject, WertikApp, WertikConfiguration } from "../types"

export const useCronJob = (cron: useCronJobsProps) => {
export const useCronJob = (cron: UseCronJobsProps) => {
return ({
configuration,
wertikApp,
Expand Down
Loading