-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from vardhanapoorv/master
update
- Loading branch information
Showing
17 changed files
with
808 additions
and
125 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,44 @@ | ||
/* | ||
* @Author: Apoorv Vardhan | ||
* @Date: 2019-09-22 23:25:03 | ||
* @Last Modified by: Apoorv Vardhan | ||
* @Last Modified time: 2019-09-22 23:46:04 | ||
*/ | ||
* @Author: Apoorv Vardhan | ||
* @Date: 2019-09-22 23:25:03 | ||
* @Last Modified by: Apoorv Vardhan | ||
* @Last Modified time: 2019-09-22 23:46:04 | ||
*/ | ||
|
||
/* | ||
TODO: Create the GraphQL setup using Apollo-Server. Refer Apollo Docs for help. | ||
TODO: Create the GraphQL setup using Apollo-Server. Refer Apollo Docs for help. | ||
*/ | ||
|
||
const mongoose = require('mongoose'); | ||
const express = require('express'); | ||
const { ApolloServer } = require('apollo-server-express'); | ||
|
||
const typeDefs = require('./graphql/typeDefs'); | ||
const resolvers = require('./graphql/resolvers/greekgod'); | ||
const models = require('./models') | ||
|
||
const app = express(); | ||
const port = 4000 || process.env.PORT; | ||
|
||
|
||
mongoose.set('useUnifiedTopology', true); | ||
|
||
mongoose.connect( | ||
`mongodb+srv://${process.env.MONGO_USER}:${process.env.MONGO_PASSWORD}@oss-contri-jmuc0.mongodb.net/${process.env.MONGO_DB}?retryWrites=true&w=majority` | ||
, {useNewUrlParser: true}).then(() => { | ||
app.listen(8000); | ||
}).catch(err => { | ||
console.log(err); | ||
, { useNewUrlParser: true }) | ||
|
||
|
||
const server = new ApolloServer({ | ||
typeDefs, | ||
resolvers, | ||
context: { models } | ||
}) | ||
|
||
server.applyMiddleware({ app }) | ||
|
||
|
||
app.listen({ port }, () => { | ||
console.log(`Server started http://localhost:${port}${server.graphqlPath}`) | ||
}).on('error', () => { | ||
console.log(error) | ||
}) |
20 changes: 10 additions & 10 deletions
20
node/greek-mythology/appwithgraphqlusingapollo/graphql/resolvers/greekgod.js
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,12 +1,12 @@ | ||
const GreekGod = require('../../models/greekgod'); | ||
|
||
module.exports = { | ||
greekGods: async () => { | ||
try { | ||
const greekGods = await GreekGod.find() | ||
return greekGods; | ||
} catch (err) { | ||
throw err; | ||
} | ||
Query: { | ||
greekGods: async (root,_,{ models }) => { | ||
try { | ||
const greekGods = await models.GreekGod.find() | ||
return greekGods; | ||
} catch (err) { | ||
throw err; | ||
} | ||
} | ||
}; | ||
}, | ||
}; |
28 changes: 0 additions & 28 deletions
28
node/greek-mythology/appwithgraphqlusingapollo/graphql/schema/index.js
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
node/greek-mythology/appwithgraphqlusingapollo/graphql/typeDefs/index.js
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,22 @@ | ||
const { gql } = require('apollo-server-express') | ||
|
||
module.exports = gql` | ||
type GreekGod { | ||
_id: ID! | ||
name: String! | ||
desc: String! | ||
} | ||
input GodInput { | ||
name: String! | ||
desc: String! | ||
} | ||
type Query { | ||
greekGods: [GreekGod!]! | ||
} | ||
type Mutation { | ||
addGod(godInput: GodInput): GreekGod | ||
}` |
5 changes: 5 additions & 0 deletions
5
node/greek-mythology/appwithgraphqlusingapollo/models/index.js
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,5 @@ | ||
const GreekGod = require('./greekgod'); | ||
|
||
module.exports = { | ||
GreekGod | ||
} |
Oops, something went wrong.