Skip to content

Commit

Permalink
Upgrade and fix server side (#1)
Browse files Browse the repository at this point in the history
* Upgrading dependencies

* upgrade prisma setup starting in section 2

* section 2: separate into trello rest proxy 2.4 and prisma setup 2.5

* section 3 and section 4: clean up server and upgrade to latest prisma version

* section 5: clean up server and upgrade to latest prisma version

* section 6: upgrade server part, including upgrading to latest prisma version

* section 7: upgrade server part, including upgrading to latest prisma version

* remove yarn.lock files

* section 6-7: remove workaround for prisma issue 2225

* section 2: upgrade server dependencies

* section 2: migrate to latest apollo-server v2

* section 6-7: server: fix resolvers, use correct graphql library
  • Loading branch information
lowsky committed May 25, 2019
1 parent 2bd4ad3 commit a047746
Show file tree
Hide file tree
Showing 65 changed files with 1,215 additions and 13,274 deletions.
File renamed without changes.
7 changes: 4 additions & 3 deletions Section2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
1. Local GraphQL Server with Database - 00:14:09


## Tutorial in Apollo launchpad:
## Tutorial in Apollo launchpad (soon-to-be-updated):

2.1 [coolboard-lists-cards-simple](https://launchpad.graphql.com/nxmqnlj917)

2.2 [coolboard-lists-cards-simple-mocks](https://launchpad.graphql.com/w53zvlpxpz)

2.3 [Trello REST wrapper](https://launchpad.graphql.com/9jl8jr7v4r)

2.4 [server/README.md](./server/README.md) for details how to start the trello-rest wrapper/proxy
## Developing and running the server locally:

2.5 [server/README.md](./server/README.md) for running the local server based on prisma
2.4 see [server/TrelloWrapper.md](./server/TrelloWrapper.md) for details how to start the trello-rest wrapper/proxy

2.5 see [server/README.md](./server/README.md) for running the local server based on prisma
65 changes: 11 additions & 54 deletions Section2/server/README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,18 @@
# Local GraphQL server based on Prisma

To run you local server, you will have to run these commands in a
terminal in this sub-folder (after a `cd server`).
terminal in this sub-folder (after a `cd server`):

First, you can startup the local database prisma server with `docker-compose up`.
* After having docker running on you local machine,
you can **start up** the prisma server with `docker-compose up -d`.

After the usual `npm install` or `yarn`, the prisma tooling is available and can be used with `npx prisma ...`:
* By running `npm install` or `yarn`, the prisma tooling will be installed and available in the next step:

`npx prisma deploy`


After having docker started on you local machine and running `docker-compose up`,
you then run `npx prisma deploy` to deploy the schema to the local (mysql) database.

Check it by opening this page in your browser: [http://localhost:4466/CoolBoardDB/dev](http://localhost:4466/CoolBoardDB/dev)


# Trello-REST-Api wrapper - quick start

To run you local server, you will have to run these commands in a
terminal in this sub-folder (after a `cd server`).

Then you will first to install all libraries per `npm install` or `yarn`.

## run apollo-express-server

```bash
yarn run start
```
and [open graphiql](http://localhost:3000/graphiql?query=%7B%0A%20%20Member(username%3A%22taco%22)%20%7B%0A%20%20%20%20id%0A%20%20%20%20url%0A%20%20%20%20username%0A%20%20%20%20boards%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20name%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D)

## run express-graphql

```bash
yarn run start-express
```
and [open graphiql](http://localhost:4000/?query=%7B%0A%20%20Member(username%3A%22taco%22)%20%0A%20%20%7B%0A%20%20%20%20id%0A%20%20%20%20username%0A%20%20%20%20url%0A%20%20%20%20boards%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20name%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)

## run graphql-yoga
```bash
yarn run start-yoga
```
and [open graphcool playground](http://localhost:4000/)

You can for example run this query:
```
{
Member(username:"taco")
{
id
username
url
boards {
id
name
}
}
}
```
* You then run `npx prisma deploy` to **deploy the schema**.

* Finally, **check** it by opening this page: [http://localhost:4466/](http://localhost:4466/) which shows the graphiql or graphql playground.
---
* Later, you can **stop** the prisma server via `docker-compose stop` ,
`docker-compose kill` ,

* For **completely removing** these docker containers you will need to run `docker-compose kill` and `docker-compose rm` which will destroy all its stored data!
58 changes: 58 additions & 0 deletions Section2/server/TrelloWrapper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Trello-REST-Api wrapper - quick start

To run you local server, you will have to run these commands in a
terminal in this sub-folder (after a `cd server`).

You will first need to install all libraries per `npm install` or `yarn`.

## run apollo-express-server

```bash
yarn run start
```
and open [http://localhost:3000/graphiql](http://localhost:3000/graphiql?query=%7B%0A%20%20Member(username%3A%22taco%22)%20%7B%0A%20%20%20%20id%0A%20%20%20%20url%0A%20%20%20%20username%0A%20%20%20%20boards%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20name%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D)
for this query:
```
{
Member(username:"taco") {
id
url
username
boards {
id
name
}
}
}
```

## run express-graphql

```bash
yarn run start-express
```
and open [http://localhost:4000](http://localhost:4000/?query=%7B%0A%20%20Member(username%3A%22taco%22)%20%0A%20%20%7B%0A%20%20%20%20id%0A%20%20%20%20username%0A%20%20%20%20url%0A%20%20%20%20boards%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20name%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)

## run graphql-yoga
```bash
yarn run start-yoga
```
and open [http://localhost:4000](http://localhost:4000/?query=%7B%0A%20%20Member(username%3A%22taco%22)%20%7B%0A%20%20%20%20id%0A%20%20%20%20url%0A%20%20%20%20username%0A%20%20%20%20boards%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20name%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D) playground


You can for example run this query:
```
{
Member(username:"taco")
{
id
username
url
boards {
id
name
}
}
}
```

Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
type Board {
id: ID! @unique
id: ID! @id
lists: [List!]!
name: String!
}
type List {
cards: [Card!]!
id: ID! @unique
id: ID! @id
name: String!
}
type Card {
id: ID! @unique
id: ID! @id
name: String!
description: String @default(value: "")
}
type User {
id: ID! @unique
id: ID! @id
email: String! @unique
password: String!
name: String!
Expand Down
33 changes: 33 additions & 0 deletions Section2/server/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: '3'
services:
prisma-handson-course:
image: prismagraphql/prisma:1.31
restart: always
ports:
- "4466:4466"
environment:
PRISMA_CONFIG: |
port: 4466
# uncomment the next line and provide the env var PRISMA_MANAGEMENT_API_SECRET=my-secret to activate cluster security
# managementApiSecret: my-secret
databases:
default:
connector: mysql
host: mysql-handson-course
user: root
password: prisma
rawAccess: true
port: 3306
migrations: true
mysql-handson-course:
image: mysql:5.7
restart: always
# Uncomment the next two lines to connect to your your database from outside the Docker environment, e.g. using a database GUI like Workbench
# ports:
# - "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: prisma
volumes:
- mysql:/var/lib/mysql
volumes:
mysql:
26 changes: 12 additions & 14 deletions Section2/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,23 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Robert Hostlowsky",
"private": "yes",
"private": true,
"devDependencies": {},
"dependencies": {
"apollo-engine": "1.1.0",
"apollo-server-express": "1.3.5",
"apollo-server-express": "2.5.0",
"babel-cli": "6.26.0",
"babel-plugin-transform-async-generator-functions": "6.24.1",
"babel-plugin-transform-object-rest-spread": "6.26.0",
"babel-plugin-transform-runtime": "6.23.0",
"babel-preset-env": "1.6.1",
"body-parser": "1.18.2",
"casual": "1.5.19",
"express": "4.16.3",
"express-graphql": "0.6.12",
"graphql": "0.13.2",
"graphql-extensions": "0.0.10",
"graphql-tools": "2.24.0",
"graphql-yoga": "1.9.2",
"node-fetch": "2.1.2",
"nodemon": "1.17.3"
"babel-preset-env": "1.7.0",
"casual": "1.6.0",
"express": "4.17.0",
"express-graphql": "0.8.0",
"graphql": "14.3.1",
"graphql-tools": "4.0.4",
"graphql-yoga": "1.17.4",
"node-fetch": "2.6.0",
"nodemon": "1.19.0",
"prisma": "1.33.0"
}
}
13 changes: 6 additions & 7 deletions Section2/server/prisma.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
service: CoolBoardDB
stage: dev
endpoint: http://localhost:4466

datamodel: datamodel.graphql
datamodel: datamodel.prisma

generate:
- generator: graphql-schema
output: schema.graphql

# to enable auth, provide
# secret: my-secret
disableAuth: true
cluster: local
36 changes: 11 additions & 25 deletions Section2/server/src/apollo-server.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,22 @@
import express from 'express';
import bodyParser from 'body-parser';

import {
graphqlExpress,
graphiqlExpress} from 'apollo-server-express';
const {ApolloServer, gql} = require('apollo-server-express');

import {schema} from './schema';

const PORT = 3000;

const server = express();

server.use('/graphql',
bodyParser.json(),
graphqlExpress({
schema,
tracing: false,
}
));

server.use('/graphiql',
graphiqlExpress({
endpointURL: '/graphql',
query: ``,
}));
const apolloServer = new ApolloServer({ schema,
debug: true,
tracing: true,
playground: true
});

server.listen(PORT, () => {
console.log(
`GraphQL Server is now running on
http://localhost:${PORT}/graphql`);
apolloServer.applyMiddleware({
path: '/graphql',
app: server });

console.log(
`View GraphiQL at
http://localhost:${PORT}/graphiql`);
});
server.listen({ port: PORT }, () => console.log(`GraphQL Server is now running on http://localhost:${PORT}${apolloServer.graphqlPath}`)
)
10 changes: 0 additions & 10 deletions Section3/server/.babelrc

This file was deleted.

3 changes: 0 additions & 3 deletions Section3/server/.gitignore

This file was deleted.

64 changes: 12 additions & 52 deletions Section3/server/README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,18 @@
# Local GraphQL server based on Prisma
# Local GraphQL server based on Prisma

To run you local server, you will have to run these commands in a
terminal in this sub-folder (after a `cd server`).
terminal in this sub-folder (after a `cd server`):

Then you will first need to install this library **global** via
`npm install -g prisma@1.5.3` or
`yarn global add prisma@1.5.3`.
* After having docker running on you local machine,
you can **start up** the prisma server with `docker-compose up -d`.

After having docker started on you local machine and running `prisma local start`,
you then run `prisma deploy` and deploy it _locally_.
* By running `npm install` or `yarn`, the prisma tooling will be installed and available in the next step:

Check it by opening this page in your browser: [http://localhost:4466/CoolBoardDB/dev](http://localhost:4466/CoolBoardDB/dev)


# Trello-REST-Api wrapper - quick start

To run you local server, you will have to run these commands in a
terminal in this sub-folder (after a `cd server`).

Then you will first to install all libraries per `npm install` or `yarn`.

## run apollo-express-server

```bash
yarn run start
```
and [open graphiql](http://localhost:3000/graphiql?query=%7B%0A%20%20Member(username%3A%22taco%22)%20%7B%0A%20%20%20%20id%0A%20%20%20%20url%0A%20%20%20%20username%0A%20%20%20%20boards%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20name%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D)

## run express-graphql

```bash
yarn run start-express
```
and [open graphiql](http://localhost:4000/?query=%7B%0A%20%20Member(username%3A%22taco%22)%20%0A%20%20%7B%0A%20%20%20%20id%0A%20%20%20%20username%0A%20%20%20%20url%0A%20%20%20%20boards%20%7B%0A%20%20%20%20%20%20id%0A%20%20%20%20%20%20name%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A)

## run graphql-yoga
```bash
yarn run start-yoga
```
and [open graphcool playground](http://localhost:4000/)

You can for example run this query:
```
{
Member(username:"taco")
{
id
username
url
boards {
id
name
}
}
}
```
* You then run `npx prisma deploy` to **deploy the schema**.

* Finally, **check** it by opening this page: [http://localhost:4466/](http://localhost:4466/) which shows the graphiql or graphql playground.
---
* Later, you can **stop** the prisma server via `docker-compose stop` ,
`docker-compose kill` ,

* For **completely removing** these docker containers you will need to run `docker-compose kill` and `docker-compose rm` which will destroy all its stored data!
Loading

0 comments on commit a047746

Please sign in to comment.