
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
create-apollo-universal
Advanced tools
Apollo Universal Starter Kit is a SEO friendly boilerplate for Universal web app development built on top of Apollo, GraphQL, React, React Native, Expo, Redux, Express with SQL storage support and Twitter Bootstrap integration. Hot Code Reload of back end & front end using Webpack and Hot Module Replacement to reflect your changes instantly and help you stay productive.
git clone https://github.com/sysgears/apollo-universal-starter-kit.git
cd apollo-universal-starter-kit
yarn
yarn seed
yarn watch
This starter kit adds full React Native integration, with Webpack as a packager and Expo. No native code compilation tools are needed in order to develop native mobile applications with this kit. You are able to run both web and mobile versions of your app at the same time connected to the same backend.
For running Android or iOS you need to set in package.json ios
or android
field true
. Currently we do not support
running both at the same time, since Expo does not support this.
You need to install Expo app on your Android or iOS device and then you can scan the QR shown in the terminal, to start the app on your device.
You can use Genymotion. After downloading and installing you might need to install VirtualBox unless you already have it. Create a new emulator and start it. After starting the server Expo app should start on it's own. To bring up the developer menu press โ+M.
You need to install Xcode. Then install Command Line Tools by running xcode-select --install
.
Next, open up Xcode, go to preferences and click the Components tab, install a simulator from the list.
After the installation if you run the server, simulator should start on it's own and open the app in Expo.
To bring up the developer menu press โ+D.
This starter kit is designed so you can use it for just web, mobile or projects using both together.
In case you do not want to use mobile, just set both ios
or android
settings in package.json to false
.
We have integrated React Native Web, so writing universal
components that can run both on web and mobile platforms
is possible. In this case you can write your components with React Native's building blocks that are supported in
React Native Web and run them both on web and mobile.
To cover more differences you can use platform-specific files.
my_component.web.jsx
my_component.android.jsx
my_component.ios.jsx
In case you only want to use it for web
and do not intend to later add mobile
version, you can omit .web.jsx
extension
and just use my_component.jsx
. Same applies if you just wish to use it for mobile
.
Currently counter
example is implemented to support web and mobile version. If you want to try running counter_show.jsx
as universal
component, just delete or rename counter_show.web.jsx
and you can see how the same component can be used
for both web and mobile.
Currently we do not yet support persisted queries. This can be used in this starter kit currently only for web, but it is planed in the future.
Webpack for back end
This starter kit is different from most of the starter kits out there, because it uses Webpack not only for front end,
but for back-end code as well. This enables powerful Webpack features for back-end code, such as conditional compilation,
embedding non-js files and CSS stylesheets into the code, hot code reload, etc. To use external backend set
serverConfig.url
at tools/webpack.app_config.js
Webpack and Expo for mobile front-end
For the best code sharing support between back-end, web front-end and mobile front-end the Webpack is used to build React Native JavaScript bundles with the help of using Haul project parts. Resulting React Native JavaScript bundles use Expo, so no native code compilation tools are needed in order to develop native mobile applications with this kit.
Hot Code Reload for back end and front end
Hot Code Reload for back end is done using Webpack. When Webpack prepares hot patches on the filesystem, SIGUSR2 signal is sent to Node.js app and embedded Webpack Hot Module Runtime reacts to this signal and applies patches to running modules from filesystem. Hot code reload for front end is using Webpack Dev Server and Hot Module Replacement to apply patches to front-end code. Hot patches for React components are applied on the front end and back end at the same time, so React should not complain about differences in client and server code.
Webpack DLL vendor bundle generation and updating out of the box
For all the non-development dependencies of project package.json
the Webpack vendor DLL bundle is generated
and updated automatically, so that Webpack didn't process vendor libraries on each change to the project, but only
when they are actually changed. This boosts speed of cold project start in development mode and speed of hot code reload
even if the number of dependencies is huge.
Server Side Rendering with Apollo Redux Store sync
On the initial web page request back end fully renders UI and hands off Apollo Redux Store state to front end. Frontend then starts off from there and updates itself on user interactions.
If you don't need Server Side Rendering, set package.json ssr
field to false
Optimistic UI updates
This example application uses Apollo optimistic UI updates, that result in immediate UI update on user interaction and then, after data arrives from the server, UI state is finalized.
GraphQL API
GraphQL is used as very flexible and much faster API in terms of bandwidth and round-trips, compared to REST. GraphQL requests are batched together automatically by Apollo
GraphQL subscription example
GraphQL subscription is utilized to make counter updating in real-time.
SQL and arbitrary data sources support
Knex code to access SQLite is included as an example of using arbitrary data source with Apollo and GraphQL. NoSQL storage or any other data source can be used the same way.
Debug SQL Prints out execuded queries, with respective times in development mode and can be set in package.json by debugSQL
field true
Powerful stylesheets with Hot Reloading
Twitter Bootstrap in form of SASS stylesheets is used for styling demo application. Application has stylesheet
in styles.scss
for global styling which is Hot Reloaded on change. React components styling is done by Glamor v3.
Babel for ES2017 transpiling
ESLint to enforce proper code style
React Hot Loader v3 for the sake of completeness this project also supports React Hot Loader v3
, but it is turned off.
By default this starter kit uses pure Webpack HMR
for all hot reloading purposes and we think it covers all
practical needs during development and using React Hot Loader v3
in addition to Webpack HMR
makes hot reloading less
predictable and buggy. To turn React Hot Loader v3
on: set reactHotLoader
field of package.json
to true
.
PersistGraphQL Webpack Plugin is a tool to gather static GraphQL queries for GraphQL projects and inject them into build. It will make front end and back end aware of static queries used in the project and will only allow these queries for better security and less bandwidth.
Dataloader for loading comments in post example
GraphQL Cursor Pagination Example ofโ Relay-style cursor pagination
Declarative/dynamic head
section, using React Helmet
Google Analytics integration using React GA
Full CRUD funcionality with Subscriptions in post example, with ReduxForm
The project structure presented in this boilerplate is fractal, where functionality is grouped primarily by feature rather than file type. This structure is only meant to serve as a guide, it is by no means prescriptive. That said, it aims to represent generally accepted guidelines and patterns for building scalable applications.
.
โโโ src # Application source code
โ โโโ client # Front-end source code
โ โ โโโ app # Common front-end application code
โ โ โโโ modules # Front-end feature-modules, each module has:
โ โ โ # (components, containers, GraphQL queries, redux reducers)
โ โ โโโ styles # Application-wide styles
โ โ โโโ test-helpers # Test helper for front-end integration tests
โ โ โโโ index.jsx # Entry point to web front-end wtih hot code reload
โ โโโ common # Common code, redux store and logging
โ โโโ mobile # Mobile front-end source code
โ โ โโโ index.js # Entry point to mobile front-end wtih live code reload
โ โโโ server # Back-end server source code
โ โ โโโ api # GraphQL API implementation
โ โ โโโ database # Database migrations and seeds
โ โ โ โโโ migrations # Database migration scripts using Knex
โ โ โ โโโ seeds # Database seed scripts using Knex
โ โ โโโ middleware # Graphiql, GraphQL express and SSR rendering
โ โ โโโ modules # Back-end server feature-modules, each module has:
โ โ โ # (schema definition, resolvers, sql queries)
โ โ โโโ sql # Knex connector
โ โ โโโ test-helpers # Test helper for back-end integration tests
โ โ โโโ api_server.js # GraphQL api server set up
โ โ โโโ index.js # Entry point to back-end wtih hot code reload
โโโ tools # All build related files (Webpack)
While developing, you will probably rely mostly on yarn watch
; however, there are additional scripts at your disposal:
npm run or yarn <script> | Description |
---|---|
watch | Run your app in develooment mode and watch your changes. Hot code reload will be enabled in development. |
start | Run your app in production mode. |
build | Compiles the application to the build folder. |
tests | Runs unit tests with Mocha. |
tests:watch | Runs unit tests with Mocha and watches for changes automatically to re-run tests. |
test | Runs unit tests with Mocha and check for lint errors |
lint | Check for lint errors and runs for all .js and .jsx files. |
seed | Seed sample database using SQLite. Use --prod flag to run in "production" mode. |
migrate | Migrate the sample database |
rollback | Rollback the sample database to previous state. |
git clone https://github.com/sysgears/apollo-universal-starter-kit.git
cd apollo-universal-starter-kit
yarn
NODE_ENV=production yarn seed
yarn build
yarn start
Settings -> Config Variables -> Add
, KEY: NPM_CONFIG_PRODUCTION
, VALUE: false
.You can see latest version of this app deployed to Heroku here: https://apollo-universal-starter-kit.herokuapp.com
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
Copyright ยฉ 2016, 2017 SysGears INC. This source code is licensed under the MIT license.
FAQs
Unknown package
We found that create-apollo-universal demonstrated a not healthy version release cadence and project activity because the last version was released a year ago.ย It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600ร faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.