Skip to content

Conversation

@RespectableRuessel
Copy link
Collaborator

@RespectableRuessel RespectableRuessel commented Dec 23, 2020

Pull request for exercise 5.
Replaced InMemoryDatasource with a Neo4j database. Now, results of mutations will be persistent.

  • Implemented connection to Neo4j
  • Refactored mutations and queries
  • Implemented tests for login and signup

Link to the review

@RespectableRuessel RespectableRuessel requested review from a team and FrauMauz and removed request for FrauMauz January 4, 2021 18:25
Copy link

@FrauMauz FrauMauz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

schon sehr komplex mittlerweile... man sieht, dass viel Arbeit drin steckt !

We wanted to broaden our horizon by using a graph database because we
only used RDBM systems.
Also the Neo4j `cypher` language looked interesting compared to regular SQL.
And we wanted to support local businesses in these dark times.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why you choosed Neo4J - short but totally ok and honest :) one 🌟 for you

```
$ npm run dev
```
but you need to start the Neo4j database service first.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice and detailed instructions + scenario architecture choosen ...1x 🌟 for you

preset: 'ts-jest',
testEnvironment: 'node',
};
testTimeout: 10000
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how did it work with the timeout of 10000? did you try other testTimeouts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also not sure why this is timeout is important? Did it fail without it?

lib
.env

dev.env
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhh the environment variables are added

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of ignore the .env , you could use git-crypt

"dev": "dotenv -e dev.env -- nodemon -e ts src/index.ts",
"lint": "eslint . --ext .ts",
"test": "jest"
"test": "dotenv -e test.env -- jest"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

environment variables for testing 👍

import {NEO4J_PASSWORD, NEO4J_URI, NEO4J_USER} from "../config/env.config";

const drv = driver(NEO4J_URI, auth.basic(NEO4J_USER, NEO4J_PASSWORD));
const db: Neo4JDatasource = new Neo4JDatasource(drv);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new Neo4JDatasource(drv); !!! good

`;

const data = await mutate({ mutation: SIGNUP_USER, variables: {
name:"Guy", email:"GUY@GUY.de", password:"123456789"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for testing.. ok

NEO4J_URI=bolt://18.204.8.8:33335
NEO4J_USER=neo4j
NEO4J_PASSWORD=twos-pages-diagnosis
NEO4J_DATABASE=
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test Variables

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⭐ For requesting a review and reviewing another team's PR.
You asked review from us.. and we are sure that you will review us as soon as you have our request. so this star will be yours for sure...

dataSources: {
databaseAPI: DatasourceAPI
};
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interface for db ... good

id: '789',
name: 'Robin',
email: 'test3@test.de',
password: generateSHA512Hash('test123')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some test users with their data and hash passwords...

Copy link
Contributor

@medizinmensch medizinmensch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Team!

I really like your thorough Readme, this made it much easier for me to review it! Thanks!

It looks like you have flaky tests. If I do npm run test, I get different errors every time - sometimes also no error.
This is because you're running your test files in parallel - jest is doing that by default. I recommend adding a --runInBand here to change that.

"test": "dotenv -e test.env -- jest --runInBand"

Otherwise a change in your database from one file affects the other.
Once that was solved it looked quite smoothly.

One thing I wonder though... Are you the group that didn't use a locally hosted db at all? So did you only use a hosted/sandbox one online? Is it possible that your test.env contains actual connection data? 😅
As you can guess, this is not how it's supposed to be.
I can only emphasize that starting one with docker is quite easy once you got docker installed. For instance with:

docker run -p 7474:7474 -p 7687:7687 --env=NEO4J_AUTH=NEO4J_USERNAME/NEO4J_PASSWORD neo4j:latest

❌ So feel free to clarify, but it looks like I can't give you a point here:

⭐ For not committing sensitive secrets (e.g. API keys) unencrypted to the repository.

❌ Secondly, I do not see that you deny your requests to your subschema. It would be easiest to set a default deny rule in your main schema so that everything not in that schema gets denied.

⭐ You deny the client to call mutations and queries of your subschema directly.

To conclude:

⭐ For choosing a scenario and writing installation instructions in README.md.
⭐ For explaining WHY you have chosen the scenario in the README.md.
⭐ ⭐ Data created in mutations are persisted and your queries and mutations still work as expected.
⭐ ⭐ Your software tests are free of side effects.
⭐ Your database is never left in an invalid state.
⭐ For requesting a review and reviewing another team's PR.

That makes 8/10 ⭐

Gif

tx.run(
"MATCH (u:User) WHERE u.id =~ $id RETURN u {.*}", {id: id}
).then(result => {
user = result.records[0].get('u')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just for fetching the first element of the returned results.

preset: 'ts-jest',
testEnvironment: 'node',
};
testTimeout: 10000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am also not sure why this is timeout is important? Did it fail without it?

@RespectableRuessel
Copy link
Collaborator Author

RespectableRuessel commented Jan 13, 2021

Hi Team!

I really like your thorough Readme, this made it much easier for me to review it! Thanks!

It looks like you have flaky tests. If I do npm run test, I get different errors every time - sometimes also no error.
This is because you're running your test files in parallel - jest is doing that by default. I recommend adding a --runInBand here to change that.

"test": "dotenv -e test.env -- jest --runInBand"

Otherwise a change in your database from one file affects the other.
Once that was solved it looked quite smoothly.

One thing I wonder though... Are you the group that didn't use a locally hosted db at all? So did you only use a hosted/sandbox one online? Is it possible that your test.env contains actual connection data? 😅
As you can guess, this is not how it's supposed to be.
I can only emphasize that starting one with docker is quite easy once you got docker installed. For instance with:

docker run -p 7474:7474 -p 7687:7687 --env=NEO4J_AUTH=NEO4J_USERNAME/NEO4J_PASSWORD neo4j:latest

❌ So feel free to clarify, but it looks like I can't give you a point here:

@medizinmensch Here is my answer to our Neo4j journey of problems:

The problem is that it seems that Neo4j can not be tested locally on your normal machine. I've written a Moodle Post about it because I looked up the issue and nobody who worked with Neo4j had an actual answer. Robert suggested to mock out the session but then you're miss testing the connection and exception handling when your database fails which is not desirable.

The only option we found (without docker) was the sandbox that was presented in the lecture. The problem with docker is that I (for example) cannot use docker because it requires "Hyper-V and Containers Windows features must be enabled" . This is not possible for me because I am using a different hypervisor which is not compatible with Hyper-V.

Unfortunately Neo4j's architecture design is bad for using multiple instances because it runs an own service that (at least in free mode) cannot automatically setup a second database for testing.
There is a in-memory API but it is only accessible through the Java library. Also running a local instance is hard because the god-damn paths include a GUID which is different between users that leads to the problem that a configuration file will not work with other users and on the CI because the paths to the Neo4j file differ.

This was the original post:

Überall steht, dass das leider nicht "einfach" möglich ist [1]. Für die Java / C# Anbindung gibt es die ImpermanentGraphDatabase [2, 3], die es aber nicht für JS oder andere Sprachen implementiert ist.

Empfohlen wird das "Mocken" der Aufrufe, welches uns aber wieder nur zur InMemoryDatasource führt, die wir ja nicht nutzen sollen. Die paar "Lösungen" die es gibt scheinen zusätzlich eine Bearbeitung der neo4j config zu benötigen [4], welches auf der CI kompliziert wird, da die lokalen neo4j Pfade nicht übereinstimmen.

[1] https://stackoverflow.com/questions/49348839/how-to-unit-test-neo4j-in-python

[2] neo4j/neo4j-javascript-driver#211

[3] https://neo4j.com/docs/java-reference/current/java-embedded/include-neo4j/

[4] https://stackoverflow.com/questions/45784232/how-to-create-new-database-in-neo4j

+++ EDIT:

I am also not sure why this is timeout is important? Did it fail without it?

This is because the sandbox is sometimes slow which leads to failed tests.

Testing got different errors/no errors each time they ran, because they ran in parallel. Hence they are tested in sequence now.
@RespectableRuessel RespectableRuessel merged commit 44c7bb7 into main Jan 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants