Skip to content

Commit 00bd059

Browse files
rootJohnny-Q
andcommitted
set up querying and mutations and MySQL queries
Co-authored-by: Johnny <[email protected]>
1 parent 0b401a7 commit 00bd059

File tree

15 files changed

+4340
-57
lines changed

15 files changed

+4340
-57
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
2-
package-lock.json
2+
package-lock.json
3+
nohup.out
4+
build

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
123,125
1+
{
2+
"extensions.ignoreRecommendations": true,
3+
"files.autoSave": "off"
4+
}

build/index.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

client.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const ws = require("ws");
2+
3+
var asdf = new ws("http://api.osn-reo.org:5000");
4+

mysql_sample_db/mysqlsampledatabase.sql

Lines changed: 4065 additions & 0 deletions
Large diffs are not rendered by default.

mysql_sample_db/sample_db.zip

53.1 KB
Binary file not shown.

package.json

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,22 @@
44
"description": "API routing for mobile app",
55
"main": "index.js",
66
"dependencies": {
7-
"@types/node": "^14.0.27",
8-
"express": "^4.17.1",
9-
"express-graphql": "^0.11.0",
7+
"apollo-datasource": "^0.7.2",
8+
"apollo-datasource-rest": "^0.9.3",
9+
"apollo-server": "^2.16.1",
1010
"firebase-admin": "^9.0.0",
11-
"graphql": "^15.3.0"
11+
"google-auth-library": "^6.0.6",
12+
"graphql": "^15.3.0",
13+
"mysql": "^2.18.1",
14+
"ws": "^7.3.1"
15+
},
16+
"devDependencies": {
17+
"@types/graphql": "^14.5.0",
18+
"@types/node": "^14.0.27"
1219
},
13-
"devDependencies": {},
1420
"scripts": {
15-
"test": "echo \"Error: no test specified\" && exit 1"
21+
"test": "echo \"Error: no test specified\" && exit 1",
22+
"start": "node build/server.js"
1623
},
1724
"repository": {
1825
"type": "git",

src/index.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/resolvers.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { rootCertificates } from "tls";
2+
3+
export {};
4+
5+
6+
module.exports = {
7+
UserInterface: {
8+
__resolveType(user, context, info){
9+
if(user.isAvailable){
10+
return 'Tutor'
11+
}
12+
else return 'Student'
13+
}
14+
},
15+
16+
Query:{
17+
hello: ()=>{
18+
return "Hello World!";
19+
},
20+
getUserById: (_, { id }, { dataSources })=> dataSources.db.getUserById(id),
21+
getMessageById: (_, { id })=>{
22+
var messages = {
23+
1:{
24+
"id": 1,
25+
"author": {
26+
"id": 1,
27+
"displayName": "johney"
28+
},
29+
"content":"hello world",
30+
"timestamp": "8/11/2020"
31+
},
32+
2:{
33+
"id": 1,
34+
"author": {
35+
"id": 2,
36+
"displayName": "bort"
37+
},
38+
"content":"hello world",
39+
"timestamp": "8/11/2020"
40+
}
41+
}
42+
return messages[id];
43+
}
44+
},
45+
Mutation:{
46+
addUser: (_, {displayName }, { dataSources })=> dataSources.db.addUser(displayName)
47+
}
48+
}

src/schema.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
export {};
2+
const { gql } = require("apollo-server");
3+
4+
const typeDefs = gql`
5+
interface UserInterface{
6+
id: Int!
7+
displayName: String!
8+
}
9+
10+
type User{
11+
id: Int!
12+
displayName: String!
13+
}
14+
15+
type Tutor implements UserInterface{
16+
id: Int!
17+
displayName: String!
18+
tutoredSubjects: [String!]!
19+
isAvailable: Boolean!
20+
}
21+
22+
type Student implements UserInterface{
23+
id: Int!
24+
displayName: String!
25+
}
26+
27+
type Message{
28+
id: Int!
29+
author: UserInterface!
30+
content: String!
31+
timestamp: String!
32+
}
33+
34+
type Channel{
35+
id: ID!
36+
users: [UserInterface!]!
37+
messages: [Message!]!
38+
}
39+
40+
type RequestTutorReturn{
41+
requestId: ID!
42+
assignedTutor: Tutor!
43+
}
44+
45+
type Query{
46+
requestTutor(reqBy: ID!, subject: String!, timestamp: String!): RequestTutorReturn
47+
getUserById(id: Int!): UserInterface
48+
getMessageById(id: Int!): Message
49+
hello: String
50+
}
51+
52+
type Mutation{
53+
deleteMessageById(id: ID!): Int!
54+
addUser(displayName: String!): UserInterface
55+
}
56+
`;
57+
58+
module.exports = typeDefs;

0 commit comments

Comments
 (0)