All Projects → yatsu → React Apollo Koa Example

yatsu / React Apollo Koa Example

Licence: mit
An example app using React, Apollo and Koa

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Apollo Koa Example

Apollo Upload Examples
A full stack demo of file uploads via GraphQL mutations using Apollo Server and apollo-upload-client.
Stars: ✭ 358 (+1276.92%)
Mutual labels:  graphql, apollo, koa
Graphql Upload
Middleware and an Upload scalar to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.
Stars: ✭ 1,071 (+4019.23%)
Mutual labels:  graphql, apollo, koa
Pup
The Ultimate Boilerplate for Products.
Stars: ✭ 563 (+2065.38%)
Mutual labels:  graphql, apollo
Apollo Fetch
🐶 Lightweight GraphQL client that supports middleware and afterware
Stars: ✭ 581 (+2134.62%)
Mutual labels:  graphql, apollo
Pizzaql
🍕 Modern OSS Order Management System for Pizza Restaurants
Stars: ✭ 631 (+2326.92%)
Mutual labels:  graphql, apollo
Chatty
A WhatsApp clone with React Native and Apollo (Tutorial)
Stars: ✭ 481 (+1750%)
Mutual labels:  graphql, apollo
Animavita
Trigger life-saving alerts, register animals for adoption and find the closest pet friend to adopt 🐶
Stars: ✭ 508 (+1853.85%)
Mutual labels:  graphql, apollo
Learnapollo
👩🏻‍🏫 Learn Apollo - A hands-on tutorial for Apollo GraphQL Client (created by Graphcool)
Stars: ✭ 5,274 (+20184.62%)
Mutual labels:  graphql, apollo
Cookiecutter Django Vue
Cookiecutter Django Vue is a template for Django-Vue projects.
Stars: ✭ 462 (+1676.92%)
Mutual labels:  graphql, apollo
Graphql
GraphQL (TypeScript) module for Nest framework (node.js) 🍷
Stars: ✭ 697 (+2580.77%)
Mutual labels:  graphql, apollo
Offix
GraphQL Offline Client and Server
Stars: ✭ 694 (+2569.23%)
Mutual labels:  graphql, apollo
Storefront Api Examples
Example custom storefront applications built on Shopify's Storefront API
Stars: ✭ 769 (+2857.69%)
Mutual labels:  graphql, apollo
Learning Graphql
The code samples for Learning GraphQL by Eve Porcello and Alex Banks, published by O'Reilly Media
Stars: ✭ 477 (+1734.62%)
Mutual labels:  graphql, apollo
Graphql Crunch
Reduces the size of GraphQL responses by consolidating duplicate values
Stars: ✭ 472 (+1715.38%)
Mutual labels:  graphql, apollo
Brian Lovin Next
My personal site
Stars: ✭ 522 (+1907.69%)
Mutual labels:  graphql, apollo
Example Storefront
Example Storefront is Reaction Commerce’s headless ecommerce storefront - Next.js, GraphQL, React. Built using Apollo Client and the commerce-focused React UI components provided in the Storefront Component Library (reactioncommerce/reaction-component-library). It connects with Reaction backend with the GraphQL API.
Stars: ✭ 471 (+1711.54%)
Mutual labels:  graphql, apollo
Learn Graphql
Real world GraphQL tutorials for frontend developers with deadlines!
Stars: ✭ 586 (+2153.85%)
Mutual labels:  graphql, apollo
Koa Graphql
Create a GraphQL HTTP server with Koa.
Stars: ✭ 787 (+2926.92%)
Mutual labels:  graphql, koa
Graphql Pokemon
Get information of a Pokémon with GraphQL!
Stars: ✭ 441 (+1596.15%)
Mutual labels:  graphql, koa
Get Graphql Schema
Fetch and print the GraphQL schema from a GraphQL HTTP endpoint. (Can be used for Relay Modern.)
Stars: ✭ 443 (+1603.85%)
Mutual labels:  graphql, apollo

react-apollo-koa-example

An example web app using React, Apollo (GraphQL), Koa v.2.

This project was generated by create-react-app and is not ejected. Some settings are overwritten on runtime though.

passport branch uses Passport to integrate authentication with social services such as Google+, Facebook, etc., whereas master branch uses simple-oauth2 to authenticate with GitHub.

screen image

Setup

Install Node.js and Yarn.

Install required packages.

% yarn

Copy .env.default to .env and edit it to change server-side settings.

Copy src/config-default.json to src/config.json and edit it to change client-side settings.

Usage

Launch the API server:

% yarn run server

Launch the development web server which serves the static client-side files:

% yarn start

Open the URL (default: http://localhost:3000) in your browser.

Frameworks/Libraries

Client-side

The application code was generated by create-react-app.

See package.json for more information.

Server-side (the API server)

See package.json for more information.

The API server does not use DB and stores data on memory. All changes will be cleared when you stop the server.

Tests

Repo and code management

GraphQL/Apollo

Persisted Queries

GraphQL querires, mutations and subscriptions are defined in src/graphql as .graphql files. They can be used as persisted queries.

You can enable persisted queries by modifying config.json.

{
    "persistedQueries": true
}

You need to generate extracted_queries.json by executing this.

% yarn run persistgraphql

Read the following article to know about persisted queries.

Subscriptions

This example project uses subscriptions. Select "GraphQL Subscription" tab in the header to see it.

Read the following article to know about subscriptions.

Authentication

JWT access token and refresh token are used to authenticate a client.

  • Access token
    • Expires in 2 hours (default)
  • Refresh token
    • Expires in 60 days (default)
    • It is used only for refreshing the access token

The access token is automatically refreshed by WebClient and Apollo client (including GraphQL subscription).

When the refresh token is expired, the user will be automatically signed out.

The WebSocket connection will also be authenticated with a JWT access token. It will be reconnected on signing in/out to do the authentication. There are two types of connection, authenticated and unauthenticated.

You can set the expiration on server-side by editing .env file.

e.g.:

ACCESS_TOKEN_EXPIRES_IN=10s
REFRESH_TOKEN_EXPIRES_IN=2h

You need to sign out and sign in again to apply the new expiration.

It is also possible to set them in client-side localStorage if the server is running on debugging mode.

Set devHeaders as the following (JSON encoded string):

{ "X-ACCESS-TOKEN-EXPIRES-IN": "10s", "X-REFRESH-TOKEN-EXPIRES-IN": "2h" }

Setting devHeaders is useful for testing. See auth_token_test.js.

Storybook

This project uses React Storybook. to develop and check presentational components.

Launch the Storybook server:

% yarn run storybook

StoryShots is also used to enable snapshot tests. When you modify a component and the render result is changed, Jest reports an error. If the shown result is intended, press u to update the snapshot file.

Code Organization

Redux actions, reducers and logic are managed by Ducks rules in src/ducks directory.

Tests are stored in __tests__ directories under each component.

Git Hooks

Git hooks are managed by Husky. When you run yarn in this repo, Git hooks will be automatically created.

If you have a problem, you can create them manually.

% node node_modules/husky/bin/install.js

Our Git hooks are defined in package.json.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].