Skip to content

Commit

Permalink
Added a new Post component to display a full page post
Browse files Browse the repository at this point in the history
  • Loading branch information
adriantoine committed Sep 12, 2015
1 parent 74c6dff commit c197b2d
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bloql",
"version": "0.3.0",
"version": "0.4.0",
"description": "Blog engine powered by blog engine powered by React using Relay and GraphQL to interact with data",
"scripts": {
"clean": "rm -rf dist/",
Expand Down
1 change: 1 addition & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
module.exports = {
createPostList: require('./client/PostList').create,
createPostItem: require('./client/PostItem').create,
createPost: require('./client/Post').create,
};
40 changes: 40 additions & 0 deletions src/client/Post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

import Relay, { RootContainer } from 'react-relay';
import React, { Component } from 'react';
import Route from './routes/PostRoute';

function createPost(Post) {
return Relay.createContainer(Post, {
fragments: {
post: () => Relay.QL`
fragment on Post {
meta {
title
slug
date
categories
tags
},
content
}
`,
},
});
}

function createRoot(Post) {
return class Root extends Component {
render() {
return (
<RootContainer Component={ Post } route={ new Route({
slug: this.props.slug
}) }/>
);
}
};
}

export const create = function (Post) {
var post = createPost(Post);
return createRoot(post);
};
4 changes: 2 additions & 2 deletions src/client/PostList.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import Relay, { RootContainer } from 'react-relay';
import React, { Component } from 'react';
import Routes from './Routes';
import Route from './routes/BlogRoute';

function createPostList(PostList, PostItem) {
return Relay.createContainer(PostList, {
Expand Down Expand Up @@ -46,7 +46,7 @@ function createRoot(Blog) {
return class Root extends Component {
render() {
return (
<RootContainer Component={ Blog } route={ new Routes() }/>
<RootContainer Component={ Blog } route={ new Route() }/>
);
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/client/Routes.js → src/client/routes/BlogRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import Relay from 'react-relay';
export default class extends Relay.Route {

static queries = {
blog: () => Relay.QL`query { blog }`,
blog: () => Relay.QL`query { blog }`
};

static routeName = 'HomeRoute';
static routeName = 'BlogRoute';

}
12 changes: 12 additions & 0 deletions src/client/routes/PostRoute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

import Relay from 'react-relay';

export default class extends Relay.Route {

static queries = {
post: () => Relay.QL`query { post(slug: $slug) }`,
};

static routeName = 'PostRoute';

}
5 changes: 0 additions & 5 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

var path = require('path');
var postsPath = 'posts';

module.exports.setConfig = function (options) {
Expand All @@ -11,7 +10,3 @@ module.exports.setConfig = function (options) {
module.exports.getPostsPath = function () {
return postsPath;
};

module.exports.getWebpackPluginPath = function () {
return path.join(__dirname, 'server', 'build', 'babelRelayPlugin');
};
18 changes: 10 additions & 8 deletions src/server/schema/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,19 @@ export const getPostList = function (filters) {
} else {

for (let filter in filters) {
if ({}.hasOwnProperty.call(filters, filter)) {

// Filter by string filter
if (STRING_FILTERS.indexOf(filter) > -1 && post.meta[filter] === filters[filter]) {
retPostList.push(post);
}
// Filter by string filter
if (_.contains(STRING_FILTERS, filter) && post.meta[filter] === filters[filter]) {
retPostList.push(post);
}

// Filter by array filter
if (ARRAY_FILTERS.indexOf(filter) > -1 && _.intersection(post.meta[filter], filters[filter]).length) {
retPostList.push(post);
}
// Filter by array filter
if (_.contains(ARRAY_FILTERS, filter) && _.intersection(post.meta[filter], filters[filter]).length) {
retPostList.push(post);
}

}
}

}
Expand Down
23 changes: 20 additions & 3 deletions src/server/schema/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,37 @@
import {
GraphQLObjectType,
GraphQLSchema,
GraphQLString,
} from 'graphql/type';

import { getBlog } from './database';
import { blogType, node } from './types';
import { getBlog, getPostList } from './database';
import { blogType, postType, node } from './types';

var Root = new GraphQLObjectType({

name: 'Root',

fields: () => ({

node: node.nodeField,

blog: {
type: blogType,
resolve: () => getBlog()
},

post: {
type: postType,
args: {
slug: {
type: GraphQLString,
},
},
resolve: (root, args) => getPostList(args)[0],
}
}),

})

});

var schema = new GraphQLSchema({
Expand Down

0 comments on commit c197b2d

Please sign in to comment.