Skip to content

Commit 0b401a7

Browse files
committed
graphql setup
1 parent 02bd603 commit 0b401a7

File tree

4 files changed

+74
-18
lines changed

4 files changed

+74
-18
lines changed

.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
123,125

build/index.js

+23-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
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');

package.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
}

src/index.ts

+23-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
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');
34

4-
const port = 420;
5+
// Construct a schema, using GraphQL schema language
6+
var schema = buildSchema(`
7+
type Query {
8+
hello: String
9+
}
10+
`);
511

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+
};
918

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');

0 commit comments

Comments
 (0)