Giter Site home page Giter Site logo

mackentoch / react-redux-graphql-apollo-bootstrap-webpack-starter Goto Github PK

View Code? Open in Web Editor NEW
126.0 17.0 33.0 5.64 MB

react js + redux + graphQL + Apollo + react router + hot reload + devTools + bootstrap + webpack starter

Home Page: https://mackentoch.github.io/react-redux-graphql-apollo-bootstrap-webpack-starter

JavaScript 100.00%
reactjs redux apollo-client graphql webpack bootstrap react react-router scaphold react-router-v4

react-redux-graphql-apollo-bootstrap-webpack-starter's Introduction

Full ES6+ React + React-Router + Redux + GraphQL + Apollo + Bootstrap with Hot Reload and redux-devtools STARTER

My new React + redux project starter. This time I add graphQL and Apollo Client. This starter also embeds JWT token based authentication (check Route to get an example of dealing with protected routes).

preview

  • webpack is as simple as possible
  • ReactJS is written with optimization tricks (stateless, pure render...).
  • pure front-end = server independant (use whatever you want as server: NodeJS, Rails, .NET...)
  • contains both SPA and SSR server implementation
  • caching implementation with workbox-webpack-plugin (so that it follows PWA path!)
  • redux + devTools + hot reload= how did I developed without them before?
  • graphQL makes API to be " has been "
    • no more struggle in redux with async thank to Apollo Client (you can even get rid of redux thunk or redux saga if you needed theses just for your asyncs. Otherwise keep them since they are nice πŸ˜„)
  • redux-devtools-extension to make developments a pure pleasure.

New πŸŽ‰ since v3.0.0!

  • Add code splitting by using dynamic import (router level but you can extend to component level as you feel the need)
  • NOTE: combined with SSR server and SW for caching, this is a good start to follow PWA path!
  • Want to know more about code splitting with SSR a React application, read this complete beautiful article (don't forget to clap the author - no I don't even know him πŸ˜‰ - but this is a really nice job)

Detailed Content

Front:

Tool chain:

  • babel 6+
  • eslint
  • hot reload
  • loaders
    • js / jsx
    • css
    • json
    • images formats
    • svg and fonts formats

tests:

  • jest

Usage

Prerequisite

Node JS version required is >=6.x.

Build with node js v8.x but should be ok with node js 6.x.

Better use nvm to manage your Node JS versions.

server

An Easy and fast way to get your graphql backend is to register for free at Scaphold.

This starter has been created with a scaphold free plan.

Go to Scaphold register and create an application

create_app_modal preview

  • set AppName
  • and a description (so that after creating hundreds of applications you won't get lost).

You will be able to dicover predefined schemas. This starter will not need more than predefined (User):

schema_desiner_overview.png

  • you can define you own schema (not needed for this starter to run). But I suggest you have a look on well written tutorials to get more familiar with the schema designer.

GraphiQL is integrated in Scaphold so discover and train predefined graphQL queries and mutations:

graphiQL_overview.png

Configure starter application:

In Scaphold click on My API and copy your application link.

Then, past it (to replace http://localhost:8080/graphql) in your networkInterface in the app config (in ./src/front/config.index.js):

export const appConfig = {
  // apollo client:
  apollo: {
    networkInterface: 'http://localhost:8080/graphql'
  }
};

from now you got all needed to run this starter

Install dependencies

npm install

run dev : hot reload mode (+ redux-devtools-extension)

npm run start

NOTE: be sure you already installed redux-devtools-extension in your browser to get the best development experience.

bundle dev mode (+ redux-devtools)

npm run dev

tests

npm run test

Analyze production bundle (PWA friendly)

npm run analyze

bundle production mode

npm run prod

run dev bundle

npm run start-spa-dev

run prod bundle

npm run start-spa-prod

Donate

Do you use & like react-redux-graphql-apollo-bootstrap-webpack-starter but you don’t find a way to show some love? If yes, please consider donating to support this project. Otherwise, no worries, regardless of whether there is support or not, I will keep maintaining this project. Still, if you buy me a cup of coffee I would be more than happy though πŸ˜„

Support via PayPal

License

The MIT License (MIT)

Copyright (c) 2019 Erwan DATIN

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

react-redux-graphql-apollo-bootstrap-webpack-starter's People

Contributors

mackentoch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-redux-graphql-apollo-bootstrap-webpack-starter's Issues

State Not Found

When you run the command

npm run dev

In the frontend the console throw:

loadable-components state not found. You have a problem server-side. Please verify that you have called loadableState.getScriptTag() server-side.

Looks like the server render can't create the initial state.

styles in css for SSR

as soon as I do import styles from './styles.css';ssr is not working anymore. Anyone already faced that problem before?

How to handle assets dev/prod?

Hi there,

I really like your boilerplate. Thanks a lot (:

The only weird thing I've noticed is how prod bundle is done. Where should I put my static files, like images, fonts?

At first I put at public folder, but then noticed that the bundle wasn't loading my assets. Also, I find it really weird that there is a index.html that is static, not copied from root folder in webpack bundle.

Did I missed something?

Thanks

Register User

I have this error when i try to test register user from app:
GraphQL error: User is not permitted to access mutation: createUser

NPM install throws a lot of peer dependency warnings

When I hit NPM install to install this package, I get the following errors:

npm ERR! Darwin 16.4.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v4.5.0
npm ERR! npm  v2.15.9
npm ERR! code EPEERINVALID

npm ERR! peerinvalid The package [email protected] does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants [email protected] || 15.* || ^15.0.0
npm ERR! peerinvalid Peer [email protected] wants react@>=0.14.0
npm ERR! peerinvalid Peer [email protected] wants react@^15.5.4
npm ERR! peerinvalid Peer [email protected] wants react@^0.14.0
npm ERR! peerinvalid Peer [email protected] wants react@>=0.13.2 || ^0.14 || ^15.0.0
npm ERR! peerinvalid Peer [email protected] wants react@^0.14.0 || ^15.0.0-0 || ^15.4.0-0 || ^16.0.0-0
npm ERR! peerinvalid Peer [email protected] wants react@^0.14.0 || ^15.0.0
npm ERR! peerinvalid Peer [email protected] wants react@^15.4.0-0
npm ERR! peerinvalid Peer [email protected] wants [email protected] || 0.14.x || ^15.0.0-0 || 15.x
npm ERR! peerinvalid Peer [email protected] wants react@^0.14.9 || ^15.3.0
npm ERR! peerinvalid Peer [email protected] wants react@^0.14.9 || ^15.3.0
npm ERR! peerinvalid Peer [email protected] wants react@^0.14.9 || ^15.3.0

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/koenhoutman/hashtracks/ui/npm-debug.log

So maybe it's a good idea to check up on the versioning of all the node modules. Have been unable to solve this yet.

Throw error when run: npm run start

Hello, i did a fresh install with the last version from Master branch using Node 8.11 and when i try start up the application throw the next error.

ERROR in ./src/front/index.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: Unexpected token (33:4)

  31 | const renderApp = RootComponent => {
  32 |   render(
> 33 |     <AppContainer warnings={false}>
     |     ^
  34 |       <RootComponent />
  35 |     </AppContainer>,
  36 |     // $FlowIgnore

Any idea about this ?

Concepts: Dynamic gql, pass down as props

I want to discuss some concepts about ability to use/switch to multiple gql query while connecting it to the same component. What I meant was something like this:
http://dev.apollodata.com/react/api-graphql.html#graphql-config-skip

export default compose(
  graphql(gql`query MyQuery1 { ... }`, { skip: props => !props.useQuery1 }),
  graphql(gql`query MyQuery2 { ... }`, { skip: props => props.useQuery1 }),
)(MyComponent);
function MyComponent({ data }) {
  // The data may be from `MyQuery1` or `MyQuery2` depending on the value
  // of the prop `useQuery1`.
  console.log(data);
}

However, this still seems very static, and "declarative". Consider you have 2 very similar Scroll components, that has exactly the same type of View. One lists the top 100 movies, the other lists all movies matching a given set of movie Director names. The only difference here would be the gql queries, and query variables for them. It'd be nice to pass the gql query down as props.

Consider these 2 views: IndexView, MoviesView.

The way i consume the dynamic gql query and connect it to the component is to create a wrapper component like this. (In comments)

const MoviesWithCusorWrapper = (props) => {
  const { gql = moviesQuery } = props;
  const Comp = compose(graphql(gql, gqlConfig), withLoading)(Movies);

  return React.createElement(Comp, props);
};

or to simplify it further (without the added recompose and gqlConfig options, only the idea of the Wrapper Component):

const MoviesWrapper = (props) => {
  const Comp = graphql(props.gql)(Movies);

  return React.createElement(Comp, props);
};

I've abstracted the wrapper component as a HOC to something like this:

import React from 'react';
import _ from 'lodash';
import { compose } from 'recompose';
import { graphql } from 'react-apollo';

const withGqlPropsHOC = (gqlDefault, { enhancers, gqlConfig }) => Comp => (props) => {
  const { gql = gqlDefault } = props;
  // preppedEnhancers takes care of undefined, single parameter, array of enhancers
  const preppedEnhancers = _.compact(Array.isArray(enhancers) ? enhancers : [enhancers]);
  const EnhancedComp = compose(graphql(gql, gqlConfig), ...preppedEnhancers)(Comp);

  return React.createElement(EnhancedComp, props);
};

export default withGqlPropsHOC;

so we can use it like this:

export default
withGqlProps(moviesQuery, { enhancers: [withLoading], gqlConfig })(Movies);

Which results in 2 different query by passing it down as props,
image
image

Is there already something similar provided by apollo-core/apollo libraries? Any thoughts?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.