Transfer relevant changes from branch neode

This commit is contained in:
Robert Schäfer 2019-02-18 12:56:38 +01:00
parent b515da66f9
commit f17242b824
11 changed files with 83 additions and 17 deletions

View File

@ -16,10 +16,12 @@ before_install:
- curl -L https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > docker-compose
- chmod +x docker-compose
- sudo mv docker-compose /usr/local/bin
- yarn global add wait-on
install:
- docker build --build-arg BUILD_COMMIT=$TRAVIS_COMMIT --target production -t humanconnection/nitro-backend:latest .
- docker-compose -f docker-compose.yml -f docker-compose.travis.yml up -d
- wait-on http://localhost:7474 && docker-compose exec neo4j migrate
script:
- docker-compose exec backend yarn run lint

View File

@ -3,15 +3,15 @@
> This Prototype tries to resolve the biggest hurdle of connecting
> our services together. This is not possible in a sane way using
> our current approach.
>
> With this Prototype we can explore using the combination of
> our current approach.
>
> With this Prototype we can explore using the combination of
> GraphQL and the Neo4j Graph Database for achieving the connected
> nature of a social graph with better development experience as we
> do not need to connect data by our own any more through weird table
> structures etc.
>
>
> #### Advantages:
> - easer data structure
> - better connected data
@ -19,10 +19,10 @@
> - more performant and better to understand API
> - better API client that uses caching
>
> We still need to evaluate the drawbacks and estimate the development
> We still need to evaluate the drawbacks and estimate the development
> cost of such an approach
## How to get in touch
## How to get in touch
Connect with other developers over [Discord](https://discord.gg/6ub73U3)
## Quick Start
@ -35,6 +35,10 @@ Before you start, fork the repository using the fork button above, then clone it
Run:
```sh
docker-compose up
# create indices etc.
docker-compose exec neo4j migrate
# if you want seed data
# open another terminal and run
docker-compose exec backend yarn run db:seed
@ -94,7 +98,7 @@ _.env_
```yaml
NEO4J_URI=bolt://localhost:7687
NEO4J_USER=neo4j
NEO4J_USERNAME=neo4j
NEO4J_PASSWORD=letmein
```
@ -116,7 +120,7 @@ Just set `MOCK=true` inside `.env` or pass it on application start.
## Seed and Reset the Database
Optionally you can seed the GraphQL service by executing mutations that
Optionally you can seed the GraphQL service by executing mutations that
will write sample data to the database:
```bash
@ -152,5 +156,5 @@ npm run test
- [x] check if sorting is working
- [x] check if pagination is working
- [ ] check if upload is working (using graphql-yoga?)
- [x] evaluate middleware
- [x] evaluate middleware
- [ ] ignore Posts and Comments by blacklisted Users

View File

@ -11,6 +11,13 @@ services:
- /nitro-backend/node_modules
command: yarn run dev
neo4j:
environment:
- NEO4J_AUTH=none
ports:
- 7687:7687
- 7474:7474
volumes:
- neo4j-data:/data
volumes:
neo4j-data:

9
docker-compose.prod.yml Normal file
View File

@ -0,0 +1,9 @@
version: "3.7"
services:
neo4j:
environment:
- NEO4J_PASSWORD=letmein
backend:
environment:
- NEO4J_PASSWORD=letmein

View File

@ -1,6 +1,12 @@
version: "3.7"
services:
neo4j:
environment:
- NEO4J_AUTH=none
ports:
- 7687:7687
- 7474:7474
backend:
image: humanconnection/nitro-backend:builder
build:

View File

@ -27,14 +27,7 @@ services:
context: neo4j
networks:
- hc-network
volumes:
- neo4j-data:/data
environment:
- NEO4J_AUTH=none
networks:
hc-network:
name: hc-network
volumes:
neo4j-data:

View File

@ -1,2 +1,3 @@
FROM neo4j:3.5.0
RUN wget https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases/download/3.5.0.1/apoc-3.5.0.1-all.jar -P plugins/
COPY migrate.sh /usr/local/bin/migrate

11
neo4j/migrate.sh Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -e
if [[ -z "${NEO4J_PASSWORD}" ]]; then
echo 'CALL db.index.fulltext.createNodeIndex("full_text_search",["Post"],["title", "content"]);' | cypher-shell
else
echo "CALL dbms.security.changePassword('${NEO4J_PASSWORD}');" | cypher-shell --username neo4j --password neo4j
echo "CREATE CONSTRAINT ON (p:Post) ASSERT p.slug IS UNIQUE;" | cypher-shell
echo "CREATE CONSTRAINT ON (c:Category) ASSERT c.slug IS UNIQUE;" | cypher-shell
echo "CREATE CONSTRAINT ON (u:User) ASSERT u.slug IS UNIQUE;" | cypher-shell
echo "CREATE CONSTRAINT ON (o:Organization) ASSERT o.slug IS UNIQUE;" | cypher-shell
fi

View File

@ -9,7 +9,7 @@ export default function () {
driver = neo4j.driver(
process.env.NEO4J_URI || 'bolt://localhost:7687',
neo4j.auth.basic(
process.env.NEO4J_USER || 'neo4j',
process.env.NEO4J_USERNAME || 'neo4j',
process.env.NEO4J_PASSWORD || 'neo4j'
)
)

View File

@ -0,0 +1,15 @@
import slugify from 'slug'
export default function uniqueSlug(string, isUnique) {
let slug = slugify(string, {
lower: true
})
if (isUnique(slug)) return slug;
let count = 0
let uniqueSlug
do {
count += 1
uniqueSlug = `${slug}-${count}`
} while(!isUnique(uniqueSlug));
return uniqueSlug;
}

View File

@ -0,0 +1,18 @@
import uniqueSlug from './uniqueSlug'
describe('uniqueSlug', () => {
it('slugifies given string', () => {
const string = 'Hello World'
const isUnique = () => true
expect(uniqueSlug(string, isUnique)).toEqual('hello-world')
})
it('increments slugified string until unique', () => {
const string = 'Hello World'
const isUnique = jest.fn()
isUnique
.mockReturnValueOnce(false)
.mockReturnValueOnce(true)
expect(uniqueSlug(string, isUnique)).toEqual('hello-world-1')
})
})