├── .babelrc
├── .gitignore
├── LICENSE
├── PATENTS
├── README.md
├── config.js
├── js
├── app.js
├── auth
│ └── Auth.js
├── components
│ ├── App
│ │ ├── App.js
│ │ ├── Description.js
│ │ ├── Footer.js
│ │ ├── Header.js
│ │ ├── Hero.js
│ │ ├── Login.js
│ │ └── Register.js
│ ├── GraphiQL
│ │ └── GraphiQL.js
│ └── HackerNewsClone
│ │ ├── HackerNewsItem.js
│ │ ├── HackerNewsItems.js
│ │ ├── Header.js
│ │ ├── Home.js
│ │ └── Logout.js
├── mutations
│ ├── LoginMutation.js
│ └── RegisterMutation.js
└── routes
│ └── HomeRoute.js
├── package.json
├── plugins
└── babelRelayPlugin.js
├── public
└── index.html
├── schema.json
├── scripts
└── updateSchema.js
└── server.js
/.babelrc:
--------------------------------------------------------------------------------
1 | {
2 | "passPerPreset": true,
3 | "presets": [
4 | "react",
5 | "es2015",
6 | "stage-0"
7 | ]
8 | }
9 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | npm-debug.log
4 | data/schema.graphql
5 | .idea/
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | BSD License
2 |
3 | For Relay Starter Kit software
4 |
5 | Copyright (c) 2013-2015, Facebook, Inc.
6 | All rights reserved.
7 |
8 | Redistribution and use in source and binary forms, with or without modification,
9 | are permitted provided that the following conditions are met:
10 |
11 | * Redistributions of source code must retain the above copyright notice, this
12 | list of conditions and the following disclaimer.
13 |
14 | * Redistributions in binary form must reproduce the above copyright notice,
15 | this list of conditions and the following disclaimer in the documentation
16 | and/or other materials provided with the distribution.
17 |
18 | * Neither the name Facebook nor the names of its contributors may be used to
19 | endorse or promote products derived from this software without specific
20 | prior written permission.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
26 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
29 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 |
--------------------------------------------------------------------------------
/PATENTS:
--------------------------------------------------------------------------------
1 | Additional Grant of Patent Rights Version 2
2 |
3 | "Software" means the Relay Starter Kit software distributed by Facebook, Inc.
4 |
5 | Facebook, Inc. ("Facebook") hereby grants to each recipient of the Software
6 | ("you") a perpetual, worldwide, royalty-free, non-exclusive, irrevocable
7 | (subject to the termination provision below) license under any Necessary
8 | Claims, to make, have made, use, sell, offer to sell, import, and otherwise
9 | transfer the Software. For avoidance of doubt, no license is granted under
10 | Facebook's rights in any patent claims that are infringed by (i) modifications
11 | to the Software made by you or any third party or (ii) the Software in
12 | combination with any software or other technology.
13 |
14 | The license granted hereunder will terminate, automatically and without notice,
15 | if you (or any of your subsidiaries, corporate affiliates or agents) initiate
16 | directly or indirectly, or take a direct financial interest in, any Patent
17 | Assertion: (i) against Facebook or any of its subsidiaries or corporate
18 | affiliates, (ii) against any party if such Patent Assertion arises in whole or
19 | in part from any software, technology, product or service of Facebook or any of
20 | its subsidiaries or corporate affiliates, or (iii) against any party relating
21 | to the Software. Notwithstanding the foregoing, if Facebook or any of its
22 | subsidiaries or corporate affiliates files a lawsuit alleging patent
23 | infringement against you in the first instance, and you respond by filing a
24 | patent infringement counterclaim in that lawsuit against that party that is
25 | unrelated to the Software, the license granted hereunder will not terminate
26 | under section (i) of this paragraph due to such counterclaim.
27 |
28 | A "Necessary Claim" is a claim of a patent owned by Facebook that is
29 | necessarily infringed by the Software standing alone.
30 |
31 | A "Patent Assertion" is any lawsuit or other action alleging direct, indirect,
32 | or contributory infringement or inducement to infringe any patent, including a
33 | cross-claim or counterclaim.
34 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Scaphold.io's HackerNews Tutorial
2 |
3 | Fork this boilerplate code to get started with a HackerNews clone built with React-Relay.
4 |
5 | Quickstart:
6 |
7 | 1) Go to Scaphold.io (https://scaphold.io).
8 |
9 | 2) Create an account and dataset.
10 |
11 | 3) Change the URL in the API manager (config.js) in the boilerplate to point to your unique Scaphold.io API URL.
12 |
13 | 4) Run with: npm start
14 |
--------------------------------------------------------------------------------
/config.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Modify the config Scaphold URL to point to your specific app.
3 | * Find the URL at the top of the page on Scaphold.io once you've created an app.
4 | * Yup. It's that easy.
5 | */
6 |
7 | var config = {
8 | scapholdUrl: "https://us-west-2.api.scaphold.io/graphql/hacker-news-tutorial"
9 | }
10 |
11 | module.exports = config;
--------------------------------------------------------------------------------
/js/app.js:
--------------------------------------------------------------------------------
1 | import 'babel-polyfill';
2 |
3 | import React from 'react';
4 | import ReactDOM from 'react-dom';
5 | import Relay from 'react-relay';
6 | import { Router, Route, IndexRoute, applyRouterMiddleware, browserHistory, routes, hashHistory } from 'react-router';
7 | import useRelay from 'react-router-relay';
8 | import config from './../config';
9 |
10 | import App from './components/App/App';
11 | import Home from './components/HackerNewsClone/Home';
12 | import GraphiQLModule from './components/GraphiQL/GraphiQL';
13 | import { HomeQueries, prepareHomeParams } from './routes/HomeRoute';
14 |
15 | var options = {};
16 | if (localStorage.scapholdAuthToken) {
17 | options.headers = {
18 | Authorization: 'Bearer ' + localStorage.scapholdAuthToken
19 | }
20 | }
21 |
22 | Relay.injectNetworkLayer(
23 | new Relay.DefaultNetworkLayer(config.scapholdUrl, options)
24 | );
25 |
26 | ReactDOM.render(
27 |
33 |
34 |
36 |
37 | ,
38 | document.getElementById('root')
39 | );
40 |
--------------------------------------------------------------------------------
/js/auth/Auth.js:
--------------------------------------------------------------------------------
1 | import Relay from 'react-relay';
2 | import RegisterMutation from './../mutations/RegisterMutation';
3 | import LoginMutation from './../mutations/LoginMutation';
4 |
5 | export function register(username, password) {
6 | return new Promise((resolve, reject) => {
7 | Relay.Store.commitUpdate(new RegisterMutation({
8 | input: {
9 | username: username,
10 | password: password
11 | },
12 | user: null
13 | }), {
14 | onSuccess: (data) => {
15 | resolve(login(username, password));
16 | },
17 | onFailure: (transaction) => {
18 | reject(transaction.getError().message);
19 | }
20 | });
21 | })
22 | }
23 |
24 | export function login(username, password) {
25 | return new Promise((resolve, reject) => {
26 | Relay.Store.commitUpdate(new LoginMutation({
27 | input: {
28 | username: username,
29 | password: password
30 | },
31 | user: null
32 | }), {
33 | onSuccess: (data) => {
34 | resolve(data);
35 | },
36 | onFailure: (transaction) => {
37 | reject(transaction.getError().message);
38 | }
39 | });
40 | })
41 | }
--------------------------------------------------------------------------------
/js/components/App/App.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import Relay from 'react-relay';
3 | import {Row, Col, Button, Jumbotron} from 'react-bootstrap';
4 | import {hashHistory} from 'react-router';
5 | import Header from './Header';
6 | import Hero from './Hero';
7 | import Description from './Description';
8 | import Footer from './Footer';
9 |
10 | class App extends React.Component {
11 | constructor(props) {
12 | super(props);
13 | }
14 |
15 | render() {
16 | if (localStorage.scapholdAuthToken) {
17 | hashHistory.push('/home');
18 | }
19 |
20 | return (
21 |