Skip to content
This repository was archived by the owner on Sep 3, 2021. It is now read-only.

Commit 84f71f0

Browse files
author
Daniel Kaminski de Souza
committed
➕ Add cache_downloads feature, automate start and start-gateway with prestarts of the neo4j server.
1 parent 8abb83e commit 84f71f0

24 files changed

+367
-104
lines changed

.env

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
NEO4J_DIST='enterprise'
2+
NEO4J_VERSION='4.2.0'
3+
APOC_VERSION='4.2.0.0'
4+
DATASTORE_VERSION='4_0'
5+
NEO4J_USER=neo4j
6+
NEO4J_PASSWORD=letmein
7+
BOLT_PORT=7687
8+
HTTP_PORT=3000
9+
NEO4J_URI="bolt://localhost:{$BOLT_PORT}"

.env.example

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
NEO4J_DIST='enterprise'
2+
NEO4J_VERSION='4.2.0'
3+
APOC_VERSION='4.2.0.0'
4+
DATASTORE_VERSION='4_0'
5+
NEO4J_USER=neo4j
6+
NEO4J_PASSWORD=letmein
7+
BOLT_PORT=7687
8+
HTTP_PORT=3000
9+
NEO4J_URI="bolt://localhost:{$BOLT_PORT}"

.gitignore

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,5 @@ test/tck/*
7171

7272
.history
7373

74-
__MACOSX
75-
neo4j
76-
77-
neo4j-enterprise*
78-
recommendations.db.zip*
74+
.download_cache
75+
neo4j

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"avaExplorer.cwd": "test"
3+
}

example/apollo-federation/gateway.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import { inventorySchema } from './services/inventory';
55
import { productsSchema } from './services/products';
66
import { reviewsSchema } from './services/reviews';
77
import neo4j from 'neo4j-driver';
8+
import dotenv from 'dotenv';
9+
10+
dotenv.config();
811

912
// The schema and seed data are based on the Apollo Federation demo
1013
// See: https://github.com/apollographql/federation-demo
1114

1215
const driver = neo4j.driver(
1316
process.env.NEO4J_URI || 'bolt://localhost:7687',
14-
neo4j.auth.basic(
15-
process.env.NEO4J_USER || 'neo4j',
16-
process.env.NEO4J_PASSWORD || 'letmein'
17-
)
17+
neo4j.auth.basic(process.env.NEO4J_USER, process.env.NEO4J_PASSWORD)
1818
);
1919

2020
// Start Accounts

package-lock.json

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@
44
"description": "A GraphQL to Cypher query execution layer for Neo4j. ",
55
"main": "./dist/index.js",
66
"scripts": {
7+
"reinstall": "sudo rm neo4j -r && npm install",
8+
"preinstall": "sudo bash ./scripts/install-neo4j.sh",
9+
"neo4j:start": "sudo bash ./scripts/start-neo4j.sh",
10+
"neo4j:stop": "sudo bash ./scripts/stop-and-clear-neo4j.sh",
11+
"prestart": "npm run neo4j:start",
712
"start": "nodemon ./example/apollo-server/movies.js --exec babel-node -e js",
813
"autogen": "nodemon ./example/autogenerated/autogen.js --exec babel-node -e js",
914
"start-middleware": "nodemon ./example/apollo-server/movies-middleware.js --exec babel-node -e js",
1015
"start-typedefs": "nodemon ./example/apollo-server/movies-typedefs.js --exec babel-node -e js",
1116
"start-interface": "DEBUG=neo4j-graphql.js nodemon ./example/apollo-server/interface-union-example.js --exec babel-node -e js",
1217
"start-gateway": "nodemon ./example/apollo-federation/gateway.js --exec babel-node -e js",
18+
"prestart-gateway": "npm run neo4j:start",
1319
"start-bookmark-example": "nodemon ./example/apollo-server/bookmarks.js --exec babel-node -e js",
1420
"start-auth-example": "JWT_SECRET=oqldBPU1yMXcrTwcha1a9PGi9RHlPVzQ nodemon ./example/apollo-server/authScopes.js --exec babel-node -e js",
1521
"build": "babel src --presets @babel/preset-env --out-dir dist",
@@ -71,11 +77,12 @@
7177
"@babel/runtime-corejs2": "^7.5.5",
7278
"apollo-server-errors": "^2.4.1",
7379
"debug": "^4.1.1",
80+
"dotenv": "^8.2.0",
81+
"graphql": "^15.4.0",
7482
"graphql-auth-directives": "^2.2.1",
83+
"graphql-tools": "^7.0.2",
7584
"lodash": "^4.17.19",
76-
"neo4j-driver": "^4.2.1",
77-
"graphql": "^15.4.0",
78-
"graphql-tools": "^7.0.2"
85+
"neo4j-driver": "^4.2.1"
7986
},
8087
"ava": {
8188
"require": [

scripts/helpers/cache.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
get_latest_download() {
4+
local cache="$1" # Save first argument in a variable
5+
local filename_glob="$2"
6+
cd $cache
7+
{ # try
8+
latest_download="$(ls -r $filename_glob | head -1)"
9+
#save your output
10+
} 2> /dev/null || {
11+
# catch
12+
# save log for exception
13+
latest_download=()
14+
}
15+
cd ..
16+
}
17+
18+
check_if_there_is_need_to_download() {
19+
local cache="$1" # Save first argument in a variable
20+
local file_URL="$2" # Save first argument in a variable
21+
local filename="$3" # Save first argument in a variable
22+
get_latest_download $cache $filename*
23+
24+
file_to_download=()
25+
if [ ! "$latest_download" ]; then
26+
file_to_download=($file_URL/$filename)
27+
fi
28+
}
29+
get_list_of_files_to_download(){
30+
# $1 cache folder
31+
# $2..n files to check if available in cache
32+
local cache="$1" # Save first argument in a variable
33+
shift # Shift all arguments to the left (original $1 gets lost)
34+
local files_info=("$@") # Rebuild the array with rest of arguments
35+
local pattern='(.*):+(.*)'
36+
37+
files_to_download=()
38+
39+
for file_info in "${files_info[@]}"
40+
do
41+
[[ $file_info =~ $pattern ]]
42+
check_if_there_is_need_to_download $cache ${BASH_REMATCH[1]} ${BASH_REMATCH[2]}
43+
files_to_download+=($file_to_download)
44+
done
45+
}

scripts/helpers/cached_download.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
source=${BASH_SOURCE[0]}
4+
5+
cached_download(){
6+
. $(dirname $source)/get_source_dir.sh
7+
local this_directory=$(get_source_dir $source)
8+
. $this_directory/cache.sh
9+
. $this_directory/download_files.sh
10+
. $this_directory/delete_duplicates.sh
11+
# $1 download_info
12+
# $2 cache_folder
13+
local cache="$1" # Save first argument in a variable
14+
shift # Shift all arguments to the left (original $1 gets lost)
15+
local files_info=("$@") # Rebuild the array with rest of arguments
16+
get_list_of_files_to_download $cache "${files_info[@]}"
17+
download_files $cache "${files_to_download[@]}"
18+
delete_duplicates $cache # just in case
19+
cached_downloads=()
20+
local pattern='(.*):+(.*)'
21+
for file_info in ${files_info[@]}
22+
do
23+
[[ $file_info =~ $pattern ]]
24+
local file_name=${BASH_REMATCH[2]}
25+
get_latest_download $cache $file_name
26+
cached_downloads+=($cache/$latest_download)
27+
done
28+
}

scripts/helpers/delete_duplicates.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
# sudo apt-get install fdupes
4+
5+
delete_duplicates(){
6+
local folder_to_look_for_duplicates="$1"
7+
fdupes -rdN $folder_to_look_for_duplicates
8+
}

0 commit comments

Comments
 (0)