Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log error redirect #2

Open
wants to merge 133 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
1f6c0d7
Sequelize now uses the config file
asishallab Sep 27, 2018
f353fc2
no test specified
vsuaste Sep 27, 2018
743b494
environmental limit for resolvers
vsuaste Oct 5, 2018
4f418c5
change search argument name
vsuaste Oct 9, 2018
16dc3f9
helper for vue table creation
vsuaste Oct 10, 2018
a339635
no include all association by default
vsuaste Oct 22, 2018
a9f9112
no include all association by default
vsuaste Oct 22, 2018
c8660f3
fixed numeration for vueTable resolver
vsuaste Oct 23, 2018
7766202
stream csv parser
vsuaste Nov 23, 2018
241a58c
Ignore all automatically generated files
YKolokoltsev Nov 25, 2018
9ef21d4
start/test scripts added
YKolokoltsev Nov 25, 2018
96dbec7
Testing scripts copied from vsuaste repo
YKolokoltsev Nov 25, 2018
1bb246c
mysql2 dependency added
YKolokoltsev Nov 29, 2018
90e528d
mysql2 dependency added
YKolokoltsev Nov 29, 2018
895a9ca
Update README.md
vsuaste Dec 4, 2018
d353380
Update README.md
vsuaste Dec 19, 2018
8cb29b1
Update README.md
vsuaste Dec 19, 2018
0f93a3c
Update README.md
vsuaste Dec 19, 2018
c0c251e
Update README.md
vsuaste Dec 19, 2018
ae2b516
JSDoc type documentation
vsuaste Jan 7, 2019
f2cdf17
JSDoc type documentation
vsuaste Jan 7, 2019
fdde7fe
Fixed bug 'Deprecation warning for String based operators'
asishallab Jan 8, 2019
4964c8d
remove outdated test files
vsuaste Jan 8, 2019
376fd36
Added scripts to evaluate whether the relational database server is r…
asishallab Jan 16, 2019
a812734
Corrected node script return values to work with BASH.
asishallab Jan 16, 2019
8da0563
Using Sequelize's 'authenticate()' to test connection.
asishallab Jan 16, 2019
c149efc
Using correct exit values
asishallab Jan 16, 2019
0e05ff8
Running migrations and server startup sequentially, exit 1 on fail of…
asishallab Jan 16, 2019
9c153f7
Failing migrations echo an ERROR to stdout.
asishallab Jan 16, 2019
612ab7f
remove outdated test files
vsuaste Jan 8, 2019
0cc316e
Merge branch 'master' of github.com:ScienceDb/graphql-server
asishallab Jan 16, 2019
d00851c
change name config file
vsuaste Jan 16, 2019
aa041d0
add user and role data models
vsuaste Jan 17, 2019
acf11ba
login functionality - test check authorization
vsuaste Jan 18, 2019
8658019
login route added
vsuaste Jan 18, 2019
8e5f610
middleware as option with acl rules
vsuaste Jan 19, 2019
f3c2611
json response token and error catching
vsuaste Jan 24, 2019
fcd2007
added user and role json models
vsuaste Jan 30, 2019
b968a78
gitignore output folders
vsuaste Jan 30, 2019
c7f321b
fix authorization function when no acl provided
vsuaste Feb 1, 2019
81f8d9f
added 'sync-request' dependency for webservices
YKolokoltsev Feb 5, 2019
85686d7
static models moved to generator
YKolokoltsev Feb 13, 2019
9144f7e
custom error in graphql server
vsuaste Feb 19, 2019
d7e3769
fix bug when originalError does not exist
vsuaste Feb 19, 2019
bd2eb3f
clean code
vsuaste Feb 21, 2019
784c7ad
Merge branch 'issue#7-custom-error-on-graphql'
vsuaste Feb 21, 2019
036c977
delete log commands
vsuaste Feb 21, 2019
bbde754
Closed #50 creation in the background and notify user via email
YKolokoltsev Feb 26, 2019
cf5f175
Merge branch 'issue_50_bulk_creation_upload'
YKolokoltsev Feb 26, 2019
5c3e372
send error unaunthorized middleware - set origin-allow
vsuaste Feb 26, 2019
24e61e6
Closed #53 sequelize independent validations
YKolokoltsev Mar 5, 2019
aac1454
Closed #50 creation in the background and notify user via email
YKolokoltsev Mar 5, 2019
f24c393
joi validator policy for delete changed
Mar 5, 2019
2521cb1
Sequelize independent validation for CSV batch upload
YKolokoltsev Mar 6, 2019
290dd1d
Added Dockerfile.graphql_server
asishallab Mar 14, 2019
998724a
JOIN models
YKolokoltsev Mar 19, 2019
e294e37
JOIN models
YKolokoltsev Mar 19, 2019
940812e
add environment variable PORT
vsuaste Mar 21, 2019
35f23ec
allow-origin environment variable
vsuaste Mar 21, 2019
5e0566c
Update README.md
vsuaste Mar 21, 2019
315bd82
join refactoring one
Mar 21, 2019
2ec665b
generic JOIN algorithm formuleted and passed first manual tests
YKolokoltsev Mar 22, 2019
6c1958f
generic JOIN algorithm formuleted and passed first manual tests
YKolokoltsev Mar 22, 2019
97747d6
docs added at module header
YKolokoltsev Mar 22, 2019
aa7e804
docs added at module header
YKolokoltsev Mar 22, 2019
fb0f468
added TODOs until issue close
YKolokoltsev Mar 22, 2019
f914896
Removed no longer needed installation of git
asishallab Mar 25, 2019
a7e9b1d
Switched to latest node:11.12.0-stretch-slim
asishallab Mar 25, 2019
938bc71
Removed '.git*' from '/usr/src/app'
asishallab Mar 25, 2019
a5af41a
Added a separate Sequelize config for the Docker setup
asishallab Mar 25, 2019
17989f1
Corrected postgres hostname to the one used in ScienceDbStarterPack
asishallab Mar 25, 2019
dc31509
Added executable permission to migrateDbAndStartServer.sh
asishallab Mar 25, 2019
726fb61
Server managed with Docker will now check for seeders and run them, i…
asishallab Mar 26, 2019
7955d06
Using a different dir in Docker
asishallab Mar 26, 2019
339d14d
Closes: #10
YKolokoltsev Mar 28, 2019
ddc09bd
JSON, CSV, Classes added
YKolokoltsev Mar 28, 2019
88b09fc
ACL in the join-models added
YKolokoltsev Mar 29, 2019
56a752a
Merge branch 'issue#54_join_models'
YKolokoltsev Mar 29, 2019
ec4622a
check models_index.js
YKolokoltsev Mar 29, 2019
22d90c8
back to regular index
YKolokoltsev Mar 29, 2019
13ef75f
Global index with JOIN tests
Apr 1, 2019
d8d4005
add date types in schema, dictionary for graphql-sequelize types
vsuaste Apr 1, 2019
9e6d23c
boolean type added to dictionary
vsuaste Apr 2, 2019
6356190
graphql-iso-date library installed
vsuaste Apr 2, 2019
e202310
Send zip in batch upload e-mail
Apr 2, 2019
416b7be
helper added for getting models attributes info
vsuaste Apr 4, 2019
18d9530
Error on batch upload corrected
Apr 10, 2019
b9f68c8
Closes #14 batch upload explicit nulls
Apr 10, 2019
e985195
Closes #12 instance of GraphQlSchema
Apr 11, 2019
a4a7784
Fixed bug #15
asishallab Apr 12, 2019
d728fc5
web service
Apr 20, 2019
11c6988
web service
Apr 20, 2019
39864c0
JOIN outputFormat selection parameter added
YKolokoltsev Apr 22, 2019
c32f626
removed TODO
Apr 22, 2019
21ba2dc
dictionary for data types added
vsuaste May 14, 2019
6889479
sequelize-operators-added
vsuaste Jun 4, 2019
955075c
date types added to dictionary
vsuaste Jun 17, 2019
2a8ded3
index for models extended as class
vsuaste Jun 21, 2019
c974ac7
models' index path
vsuaste Jun 24, 2019
f3a3bff
typo in models' path fixed
vsuaste Jun 24, 2019
af5fa39
models' index path
vsuaste Jun 24, 2019
c839ae2
Sequelize required in models' index
vsuaste Jun 24, 2019
2645597
Fixed vulnerabilities and added Ajv
asishallab Jun 28, 2019
e325a74
Adjusted to async validation
asishallab Jun 28, 2019
2f34fd1
sequelize working with operators until new fix
vsuaste Jul 3, 2019
c5473c7
new validation sintax in file tools
vsuaste Jul 4, 2019
0c41ccf
catch error from new validation
vsuaste Jul 4, 2019
31ee4cc
index model used within the models
vsuaste Jul 18, 2019
8ec1874
search param considered in join models util
vsuaste Jul 19, 2019
3da4047
merge master with date-types-allowed
vsuaste Aug 12, 2019
cdd0299
missing comma in dictionary
vsuaste Aug 12, 2019
7b7cdc2
Merged async-validation with master
asishallab Aug 20, 2019
0d200e0
Switched from sync Joi to async AJV validator
asishallab Aug 20, 2019
ba02caa
Removed unwanted file tmp.txt
asishallab Aug 20, 2019
11a0fc6
Added util function to define AJV ISO Date-Time keywords.
asishallab Aug 20, 2019
02f9eac
Debugged return value of 'addDateTimeAjvKeywords'
asishallab Aug 20, 2019
fe87c32
Debugged missing require('ajv')
asishallab Aug 20, 2019
7c52910
merging master with async validation
vsuaste Aug 29, 2019
f657e1a
Debugged bulkCreate from streamed CSV.
asishallab Sep 5, 2019
1428e9f
Server nows expects signed in user
asishallab Sep 19, 2019
50f598e
simple export route added
vsuaste Sep 24, 2019
0c93bb9
simple export function tested
vsuaste Sep 24, 2019
33f853a
evironmental variable REQUIRE_SIGN_IN
vsuaste Sep 24, 2019
339d440
default REQUIRE_SIGN_IN to true
vsuaste Sep 24, 2019
988bdf0
test require_sign_in variable
vsuaste Sep 25, 2019
e343c15
require_sign_in variable as string
vsuaste Sep 25, 2019
f797459
Update LICENSE
AliciaMstt Sep 25, 2019
2e2cf0c
Merge branch 'master' into simple-export-route
vsuaste Sep 25, 2019
6b46aa8
csv stream export functionality
vsuaste Sep 25, 2019
d5aa51d
form request parsing
vsuaste Sep 26, 2019
1ad2398
csv extension for export file
vsuaste Sep 27, 2019
e1f99eb
Merge branch 'master' of https://github.com/ScienceDb/graphql-server
vsuaste Sep 27, 2019
8215cff
added error log redirection
framirez07 Oct 16, 2019
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
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# IntelliJ Idea project settings folder
.idea

# NPM package manager temporary files and folders
node_modules
npm-debug.log
package-lock.json

# ModelGen output folders
migrations
models
models-webservice
resolvers
schemas
test
validations
patches
15 changes: 15 additions & 0 deletions Dockerfile.graphql_server
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:11.12.0-stretch-slim

# Create app directory
WORKDIR /usr/ScienceDbStarterPack/graphql-server

# Copy generated code into the skeleton GraphQL-Server
COPY . .

# Clone the skeleton project and install dependencies
RUN chmod u+x ./migrateDbAndStartServer.sh && \
rm .git* && \
mv ./config/config_postgres_docker.json ./config/config.json && \
npm install

EXPOSE 3000
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# GraphQL backend
Skeleton NodeJS project for a graphQL server.

This package integrates the code generated by [code-generator](https://github.com/vsuaste/express_graphql_model_gen).
This package integrates the code generated by [code-generator](https://github.com/ScienceDb/graphql-server-model-codegen).

[Code-generator](https://github.com/vsuaste/express_graphql_model_gen) will generate four folders with the models' information:
[Code-generator](https://github.com/ScienceDb/graphql-server-model-codegen) will generate four folders with the models' information:
* models
* schemas
* resolvers
Expand All @@ -12,18 +12,26 @@ This package integrates the code generated by [code-generator](https://github.co
After getting ready the generated code for the models, proceed with the server set up.

## Set up

Clone the repository and run:
```
$ npm install
$ node_modules/.bin/sequelize db:migrate
$ node server.js
$ npm start
```

``` $ node_modules/.bin/sequelize db:migrate ``` command will create the tables specified in the ```migrations``` folder.
With credential as in ``` config/config.json``` file.
### ENVIRONMENT VARIABLES

* `PORT` - The port where the app is listening, default value is `3000`
* `ALLOW_ORIGIN` - In development mode we need to specify the header `Access-Control-Allow-Origin` so the SPA application can communicate with the server, default value `http://localhost:8080`.

## NOTE
A data base should be already configured locally as in `config/config.json`

## Example of use
If you followed the example for generating the code described [here](https://github.com/vsuaste/express_graphql_model_gen), you can try the next queries and mutations. Otherwise, just adapt the same queries and mutations for your own models generated.
If you followed the example for generating the code described [here](https://github.com/ScienceDb/graphql-server-model-codegen), you can try the next queries and mutations. Otherwise, just adapt the same queries and mutations for your own models generated.

We will add the next 4 people to our table ``people``.

Expand Down Expand Up @@ -65,7 +73,7 @@ curl -XPOST http://localhost:3000/graphql -H 'Content-Type: application/graphql'
We'll search people with 'science' as substring of their email and as result we'll get only their name and last name.

```
curl -XPOST http://localhost:3000/graphql -H 'Content-Type: application/graphql' -d '{ searchPerson(input:{field:email, value:{value:"%science%"}, operator:like}){ firstName lastName}}'
curl -XPOST http://localhost:3000/graphql -H 'Content-Type: application/graphql' -d '{ people(search:{field:email, value:{value:"%science%"}, operator:like}){ firstName lastName}}'
```
The result will be:

Expand Down
4 changes: 2 additions & 2 deletions acl_rules.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module.exports = {
aclRules: [{
roles: 'administrator',
roles: 'admin',
allows: [{
resources: '*',
resources: ['users', 'roles'],
permissions: '*'
}]
},
Expand Down
25 changes: 14 additions & 11 deletions config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@
"password": "test_code_gen",
"database": "test_code_gen",
"host": "127.0.0.1",
"dialect": "postgres"
"dialect": "postgres",
"operatorsAliases": false
},
"test": {
"username": "test_code_gen",
"password": "test_code_gen",
"database": "test_code_gen",
"host": "127.0.0.1",
"dialect": "postgres"
"username": "sciencedb",
"password": "sciencedb",
"database": "sciencedb_test",
"host": "postgres",
"dialect": "postgres",
"operatorsAliases": false
},
"production": {
"username": "test_code_gen",
"password": "test_code_gen",
"database": "test_code_gen",
"host": "127.0.0.1",
"dialect": "postgres"
"username": "sciencedb",
"password": "sciencedb",
"database": "sciencedb_production",
"host": "postgres",
"dialect": "postgres",
"operatorsAliases": false
}
}
26 changes: 26 additions & 0 deletions config/config_postgres_docker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"development": {
"username": "sciencedb",
"password": "sciencedb",
"database": "sciencedb_development",
"host": "sdb_postgres",
"dialect": "postgres",
"operatorsAliases": false
},
"test": {
"username": "sciencedb",
"password": "sciencedb",
"database": "sciencedb_test",
"host": "sdb_postgres",
"dialect": "postgres",
"operatorsAliases": false
},
"production": {
"username": "sciencedb",
"password": "sciencedb",
"database": "sciencedb_production",
"host": "sdb_postgres",
"dialect": "postgres",
"operatorsAliases": false
}
}
10 changes: 10 additions & 0 deletions config/globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
LIMIT_RECORDS : process.env.LIMIT_RECORDS || 10000,
PORT : process.env.PORT || 3000,
ALLOW_ORIGIN: process.env.ALLOW_ORIGIN || "http://localhost:8080",
REQUIRE_SIGN_IN: process.env.REQUIRE_SIGN_IN || "true",
MAIL_SERVICE: "gmail",
MAIL_HOST: "smtp.gmail.com",
MAIL_ACCOUNT: "[email protected]",
MAIL_PASSWORD: "SciDbServiceQAZ"
}
26 changes: 13 additions & 13 deletions connection.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
Sequelize = require('sequelize');
const env = process.env.NODE_ENV || 'development';
const path = require('path')
const config = require(path.join(__dirname, 'config', 'config.json'))[env];
const Sequelize = require('sequelize');

const Op = Sequelize.Op;
const operatorsAliases = {
config.operatorsAliases = {
$eq: Op.eq,
$and: Op.and,
$or: Op.or,
$like: Op.like,
$between: Op.between,
$in: Op.in
$in: Op.in,
$gt: Op.gt,
$gte: Op.gte,
$lt: Op.lt,
$lte: Op.lte,
$ne: Op.ne
};

sequelize = new Sequelize(
'test_code_gen',
'test_code_gen',
'test_code_gen',
{
dialect: 'postgres',
host: '127.0.0.1'
},
{operatorsAliases}
);
sequelize = new Sequelize(config);

module.exports = sequelize;
30 changes: 30 additions & 0 deletions migrateDbAndStartServer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# Wait until the relational database-server up and running
waited=0
until node ./utils/testSequelizeDbServerAvailable.js
do
if [ $waited == 240 ]; then
echo -e '\nERROR: Time out reached while waiting for relational database server to be available.\n'
exit 1
fi
sleep 2
waited=$(expr $waited + 2)
done

# Run the migrations
if ! ./node_modules/.bin/sequelize db:migrate; then
echo -e '\nERROR: Migrating the relational database(s) caused an error.\n'
exit 1
fi

# Run seeders if needed
if [ -d ./seeders ]; then
if ! ./node_modules/.bin/sequelize db:seed:all; then
echo -e '\nERROR: Seeding the relational database(s) caused an error.\n'
exit 1
fi
fi

# Start GraphQL-server
npm start 2> /usr/src/app/error_server.log # acl
64 changes: 64 additions & 0 deletions models_index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
sequelize = require('./connection');

var models = {};
module.exports = models;

// **********************************************************************************
// IMPORT SEQUEILIZE MODELS

//grabs all the models in your models folder, adds them to the models object
fs.readdirSync("./models")
.filter(function(file) {
return (file.indexOf('.') !== 0) && (file !== 'index.js') && (file.slice(-3) === '.js');
})
.forEach(function(file) {
console.log(file);
let model_file = require(path.join(__dirname,'models', file));
let model = model_file.init(sequelize, Sequelize);


let validator_patch = path.join('./validations', file);
if(fs.existsSync(validator_patch)){
model = require(`./${validator_patch}`).validator_patch(model);
}

let patches_patch = path.join('./patches', file);
if(fs.existsSync(patches_patch)){
model = require(`./${patches_patch}`).logic_patch(model);
}

if(models[model.name])
throw Error(`Duplicated model name ${model.name}`);

models[model.name] = model;

});
//Important: creates associations based on associations defined in associate function in the model files
Object.keys(models).forEach(function(modelName) {
if (models[modelName].associate) {
models[modelName].associate(models);
}
});
//update tables with association (temporary, just for testing purposes)
//this part is suppose to be done in the migration file
//sequelize.sync({force: true});


// **********************************************************************************
// IMPORT WEBSERVICES

fs.readdirSync("./models-webservice")
.filter(function(file) {
return (file.indexOf('.') !== 0) && (file !== 'index.js') && (file.slice(-3) === '.js');
})
.forEach(function(file) {
let model = require(`./${path.join("./models-webservice", file)}`);

if(models[model.name])
throw Error(`Duplicated model name ${model.name}`);

models[model.name] = model;
});
Loading