Skip to content

Commit ed4b523

Browse files
author
oleksii
committed
inital commit; first stage
0 parents  commit ed4b523

File tree

6 files changed

+1674
-0
lines changed

6 files changed

+1674
-0
lines changed

.env.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
HOST_PORT=
2+
NODE_ENV=

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/node_modules
2+
yarn-error.log
3+
.env

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# nodejs+express+graphql app
2+
based on [`this`][1] blog post
3+
4+
**before moving forward you have check if current packages installed (_latest versions_)**
5+
- [nodejs][3]
6+
- [yarn][4]
7+
8+
## to run first sage simply run**
9+
```yarn run server```
10+
11+
**proper requset should be:**
12+
13+
```
14+
{
15+
message
16+
}
17+
```
18+
19+
20+
21+
[1]: https://medium.com/codingthesmartway-com-blog/creating-a-graphql-server-with-node-js-and-express-f6dddc5320e1
22+
[3]: https://nodejs.org/en/download/
23+
[4]: https://yarnpkg.com/en/docs/install

package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "nodejs-graphql",
3+
"version": "1.0.0",
4+
"description": "test nodejs express graphql stack",
5+
"main": "server.js",
6+
"license": "MIT",
7+
"private": false,
8+
"scripts": {
9+
"standard-fix": "standard --fix",
10+
"server": "node server.js"
11+
},
12+
"dependencies": {
13+
"dotenv": "^5.0.1",
14+
"express": "^4.16.3",
15+
"express-graphql": "^0.6.12",
16+
"graphql": "^0.13.2"
17+
},
18+
"devDependencies": {
19+
"standard": "^11.0.1"
20+
}
21+
}

server.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const express = require('express')
2+
const expressGraphql = require('express-graphql')
3+
const { buildSchema } = require('graphql')
4+
require('dotenv').config()
5+
6+
// GraphQL schema with Interface Definition Language (IDL)
7+
const schema = buildSchema(`
8+
type Query {
9+
message: String
10+
}
11+
`)
12+
13+
// Root resolver
14+
let root = {
15+
message: () => 'Hello World!'
16+
}
17+
18+
// Createing an express server and a GraphQL endpoint
19+
const app = express()
20+
app.use('/graphql', expressGraphql({
21+
schema: schema,
22+
rootValue: root,
23+
graphiql: true
24+
}))
25+
26+
let port = process.env.HOST_PORT || 4000
27+
28+
app.listen(port, 'localhost', err => {
29+
if (err) {
30+
console.log(err)
31+
}
32+
33+
console.log(`Express GraphQL Server Now Running On localhost:${port}/graphql`)
34+
})

0 commit comments

Comments
 (0)