-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2c8140c
Showing
4 changed files
with
101 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
.vscode | ||
yarn.lock |
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,63 @@ | ||
const express = require('express'); | ||
const bodyParser = require('body-parser'); | ||
const { graphqlExpress, graphiqlExpress } = require('apollo-server-express'); | ||
const { makeExecutableSchema } = require('graphql-tools'); | ||
|
||
const typeDefs = require('./typeDefs.gql'); | ||
|
||
const buoyantair = { | ||
id: 0, | ||
name: "buoyantair", | ||
secret: "123" | ||
} | ||
|
||
const posts = [ | ||
{ | ||
title: "Post title", | ||
author: buoyantair, | ||
comments: [ | ||
{ | ||
author: buoyantair, | ||
desc: "Not bad", | ||
}, | ||
{ | ||
author: buoyantair, | ||
desc: "bad", | ||
} | ||
] | ||
}, | ||
{ | ||
title: "Another title", | ||
author: buoyantair, | ||
comments: [ | ||
{ | ||
author: buoyantair, | ||
desc: "This is cool", | ||
} | ||
] | ||
} | ||
]; | ||
|
||
const resolvers = { | ||
Query: { | ||
allPosts: () => posts | ||
} | ||
} | ||
|
||
const schema = makeExecutableSchema({ | ||
typeDefs, | ||
resolvers | ||
}); | ||
|
||
const app = express(); | ||
|
||
app.use('/graphql', bodyParser.json(), graphqlExpress({ schema })); | ||
|
||
app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' })); | ||
|
||
app.listen(3001, () => { | ||
console.log(` | ||
Server running at http://localhost:3001/ | ||
GraphiQL running at http://localhost:3001/graphiql/ | ||
`) | ||
}) |
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,13 @@ | ||
{ | ||
"name": "hackernews", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"apollo-server-express": "^1.3.2", | ||
"body-parser": "^1.18.2", | ||
"express": "^4.16.2", | ||
"graphql": "^0.12.3", | ||
"graphql-tools": "^2.14.1" | ||
} | ||
} |
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 @@ | ||
module.exports = ` | ||
type User { | ||
id: Int! | ||
name: String! | ||
secret: String! | ||
} | ||
|
||
type Comment { | ||
author: User! | ||
desc: String! | ||
} | ||
|
||
type Post { | ||
title: String! | ||
author: User! | ||
comments: [Comment] | ||
} | ||
|
||
type Query { | ||
allPosts: [Post] | ||
} | ||
`; |