-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This removes koa, but we can add it back should we need it again Apolo-server-2 comes with playground, which is better than graphiql
- Loading branch information
Showing
13 changed files
with
824 additions
and
889 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const hours = new Date().getHours(); | ||
const isDayTime = hours >= 6 && hours <= 18; | ||
|
||
export default { | ||
settings: { | ||
'editor.theme': isDayTime ? 'light' : 'dark', | ||
'editor.cursorShape': 'underline', | ||
'tracing.hideTracingResponse': false, | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,111 @@ | ||
import Koa from 'koa'; | ||
import { ApolloServer, gql } from 'apollo-server'; | ||
import _ from 'lodash'; | ||
import playgroundConfig from './config/graphqlPlayground'; | ||
import log from './util/log'; | ||
import jsonData from './jsonData'; | ||
|
||
import Router from 'koa-router'; | ||
import bodyParser from 'koa-bodyparser'; | ||
import { graphqlKoa, graphiqlKoa } from 'apollo-server-koa'; | ||
import koaPlayground from 'graphql-playground-middleware-koa'; | ||
const typeDefs = gql` | ||
# Describes a module for, may span different semesters | ||
type Module { | ||
code: String! | ||
title: String! | ||
department: String | ||
description: String | ||
credit: Float | ||
workload: String | ||
prerequisite: String | ||
corequisite: String | ||
corsBiddingStats: [CorsBiddingStats] | ||
# Refers to the history of the module throughout semesters | ||
history: [ModuleInfo]! | ||
} | ||
import Boom from 'boom'; | ||
import loggerMiddleware from 'koa-bunyan-logger'; | ||
import errorMiddleware from './middleware/error'; | ||
# Describes a particular module for a semester | ||
type ModuleInfo { | ||
semester: Int | ||
examDate: String | ||
examOpenBook: Boolean | ||
examDuration: String | ||
examVenue: String | ||
timetable: [Lesson] | ||
} | ||
import log from './util/log'; | ||
import schema from './graphql'; | ||
|
||
const app = new Koa(); | ||
const router = new Router(); | ||
|
||
// Register middleware | ||
app.use(bodyParser()); | ||
app.use(loggerMiddleware(log)); | ||
app.use(loggerMiddleware.requestIdContext()); | ||
app.use(loggerMiddleware.requestLogger()); | ||
app.use(errorMiddleware()); | ||
|
||
// Registers routes | ||
router.post('/graphql', graphqlKoa({ schema, tracing: true })); | ||
router.get('/graphiql', graphiqlKoa({ endpointURL: '/graphql' })); | ||
router.get('/playground', koaPlayground({ endpoint: '/graphql' })); | ||
|
||
app.use(router.routes()); | ||
app.use( | ||
router.allowedMethods({ | ||
throw: true, | ||
notImplemented: () => new Boom.notImplemented(), // eslint-disable-line new-cap | ||
methodNotAllowed: () => new Boom.methodNotAllowed(), // eslint-disable-line new-cap | ||
}), | ||
); | ||
|
||
log.info('current environment: %s', process.env.NODE_ENV); | ||
log.info('server started at port: %d', process.env.PORT || 3600); | ||
app.listen(process.env.PORT || 3600); | ||
# Bidding stats for Cors | ||
type CorsBiddingStats { | ||
quota: Int | ||
bidders: Int | ||
lowestBid: Int | ||
lowestSuccessfulBid: Int | ||
highestBid: Int | ||
faculty: String | ||
studentAcctType: String | ||
acadYear: String | ||
semester: Int | ||
round: String | ||
group: String | ||
} | ||
# A lesson conducted, may it be a lecture, laboratory or lecture | ||
type Lesson { | ||
classNo: String! | ||
lessonType: String! | ||
weekText: String! | ||
dayText: String! | ||
startTime: String! | ||
endTime: String! | ||
venue: String! | ||
} | ||
# the schema allows the following query: | ||
type Query { | ||
modules(acadYear: String!, first: Int, offset: Int): [Module!]! | ||
module(acadYear: String!, code: String!): Module | ||
} | ||
schema { | ||
query: Query | ||
} | ||
`; | ||
|
||
const resolvers = { | ||
Query: { | ||
modules(root, { acadYear, first, offset }) { | ||
const yearData = jsonData[acadYear]; | ||
if (yearData == null) { | ||
return []; | ||
} | ||
const modules = Object.values(yearData); | ||
return modules.slice(offset, offset ? offset + first : first); | ||
}, | ||
module(root, { acadYear, code }) { | ||
return _.get(jsonData, [acadYear, code]); | ||
}, | ||
}, | ||
}; | ||
|
||
const server = new ApolloServer({ | ||
typeDefs, | ||
/* Apollo is mutating resolvers */ | ||
resolvers: { ...resolvers }, | ||
playground: playgroundConfig, | ||
formatError: (error) => { | ||
log.error(error); | ||
return error; | ||
}, | ||
formatResponse: (response) => { | ||
log.info(response); | ||
return response; | ||
}, | ||
}); | ||
|
||
if (process.env.NODE_ENV !== 'test') { | ||
server.listen().then(({ url }) => { | ||
log.info(`🚀 Server ready at ${url}`); | ||
}); | ||
} | ||
|
||
/* For testing purposes */ | ||
export default { | ||
typeDefs, | ||
resolvers, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.