File tree Expand file tree Collapse file tree 6 files changed +1674
-0
lines changed Expand file tree Collapse file tree 6 files changed +1674
-0
lines changed Original file line number Diff line number Diff line change 1+ HOST_PORT=
2+ NODE_ENV=
Original file line number Diff line number Diff line change 1+ /node_modules
2+ yarn-error.log
3+ .env
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ } )
You can’t perform that action at this time.
0 commit comments