File tree 4 files changed +74
-18
lines changed
4 files changed +74
-18
lines changed Original file line number Diff line number Diff line change
1
+ 123 ,125
Original file line number Diff line number Diff line change 1
- const express = require ( "express" ) ;
2
- const app = express ( ) ;
3
- const port = 420 ;
4
- app . get ( "/" , ( req , res ) => {
5
- res . send ( "Hello World" ) ;
6
- } ) ;
7
- app . listen ( port , ( ) => {
8
- console . log ( "server started on port " + port ) ;
9
- } ) ;
1
+ var express = require ( 'express' ) ;
2
+ var { graphqlHTTP } = require ( 'express-graphql' ) ;
3
+ var { buildSchema } = require ( 'graphql' ) ;
4
+ // Construct a schema, using GraphQL schema language
5
+ var schema = buildSchema ( `
6
+ type Query {
7
+ hello: String
8
+ }
9
+ ` ) ;
10
+ // The root provides a resolver function for each API endpoint
11
+ var root = {
12
+ hello : ( ) => {
13
+ return 'Hello world!' ;
14
+ } ,
15
+ } ;
16
+ var app = express ( ) ;
17
+ app . use ( '/graphql' , graphqlHTTP ( {
18
+ schema : schema ,
19
+ rootValue : root ,
20
+ graphiql : true ,
21
+ } ) ) ;
22
+ app . listen ( 4000 ) ;
23
+ console . log ( 'Running a GraphQL API server at http://localhost:4000/graphql' ) ;
Original file line number Diff line number Diff line change
1
+ {
2
+ "name" : " app_server" ,
3
+ "version" : " 1.0.0" ,
4
+ "description" : " API routing for mobile app" ,
5
+ "main" : " index.js" ,
6
+ "dependencies" : {
7
+ "@types/node" : " ^14.0.27" ,
8
+ "express" : " ^4.17.1" ,
9
+ "express-graphql" : " ^0.11.0" ,
10
+ "firebase-admin" : " ^9.0.0" ,
11
+ "graphql" : " ^15.3.0"
12
+ },
13
+ "devDependencies" : {},
14
+ "scripts" : {
15
+ "test" : " echo \" Error: no test specified\" && exit 1"
16
+ },
17
+ "repository" : {
18
+ "type" : " git" ,
19
+ "url" : " git+https://github.com/OracleStudentNetwork/app_server.git"
20
+ },
21
+ "author" : " " ,
22
+ "license" : " ISC" ,
23
+ "bugs" : {
24
+ "url" : " https://github.com/OracleStudentNetwork/app_server/issues"
25
+ },
26
+ "homepage" : " https://github.com/OracleStudentNetwork/app_server#readme"
27
+ }
Original file line number Diff line number Diff line change 1
- const express = require ( "express" ) ;
2
- const app = express ( ) ;
1
+ var express = require ( 'express' ) ;
2
+ var { graphqlHTTP } = require ( 'express-graphql' ) ;
3
+ var { buildSchema } = require ( 'graphql' ) ;
3
4
4
- const port = 420 ;
5
+ // Construct a schema, using GraphQL schema language
6
+ var schema = buildSchema ( `
7
+ type Query {
8
+ hello: String
9
+ }
10
+ ` ) ;
5
11
6
- app . get ( "/" , ( req , res ) => {
7
- res . send ( "Hello World" ) ;
8
- } ) ;
12
+ // The root provides a resolver function for each API endpoint
13
+ var root = {
14
+ hello : ( ) => {
15
+ return 'Hello world!' ;
16
+ } ,
17
+ } ;
9
18
10
- app . listen ( port , ( ) => {
11
- console . log ( "server started on port " + port ) ;
12
- } ) ;
19
+ var app = express ( ) ;
20
+ app . use ( '/graphql' , graphqlHTTP ( {
21
+ schema : schema ,
22
+ rootValue : root ,
23
+ graphiql : true ,
24
+ } ) ) ;
25
+ app . listen ( 4000 ) ;
26
+ console . log ( 'Running a GraphQL API server at http://localhost:4000/graphql' ) ;
You can’t perform that action at this time.
0 commit comments