Skip to content

Commit

Permalink
Basic structure for simple blog
Browse files Browse the repository at this point in the history
  • Loading branch information
elevenpassin committed Dec 20, 2017
0 parents commit 2c8140c
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.vscode
yarn.lock
63 changes: 63 additions & 0 deletions app.js
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/
`)
})
13 changes: 13 additions & 0 deletions package.json
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"
}
}
22 changes: 22 additions & 0 deletions typeDefs.gql
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]
}
`;

0 comments on commit 2c8140c

Please sign in to comment.