Skip to content

Commit

Permalink
Setup basic schema & resolvers for the blog, init client
Browse files Browse the repository at this point in the history
  • Loading branch information
elevenpassin committed Dec 20, 2017
1 parent 34fc790 commit 810e02e
Show file tree
Hide file tree
Showing 17 changed files with 2,562 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
*/node_modules
.vscode
yarn.lock
72 changes: 49 additions & 23 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,70 @@
const { find, filter } = require('lodash');
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 users = [
{
userid: 0,
name: "buoyantair",
secret: "123"
},
{
userid: 1,
name: "raxx",
secret: "456"
}
];

const comments = [
{
commentid: 0,
postid: 1,
userid: 1,
desc: "This is cool",
},
{
commentid: 1,
postid: 0,
userid: 0,
desc: "Not bad",
},
{
commentid: 2,
postid: 0,
userid: 1,
desc: "bad",
}
];

const posts = [
{
title: "Post title",
author: buoyantair,
comments: [
{
author: buoyantair,
desc: "Not bad",
},
{
author: buoyantair,
desc: "bad",
}
]
userid: 0,
postid: 0,
},
{
title: "Another title",
author: buoyantair,
comments: [
{
author: buoyantair,
desc: "This is cool",
}
]
userid: 0,
postid: 1,
}
];

const resolvers = {
User: {
posts: (user) => filter(posts, { userid: user.userid }),
comments: (user) => filter(comments, { userid: user.userid })
},
Comment: {
user: (comment) => find(users, { userid: comment.userid })
},
Post: {
user: (post) => find(users, { userid: post.userid }),
comments: (post) => filter(comments, { postid: post.postid })
},
Query: {
allPosts: () => posts
}
Expand Down
21 changes: 21 additions & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
Loading

0 comments on commit 810e02e

Please sign in to comment.