Kick off your project with this default boilerplate. This starter ships with the main Gatsby configuration files you might need to get up and running blazing fast with the blazing fast app generator for React.
-
Gatsby.js for client side
- Styled-component
- Material-UI
- PWA (optional)
-
Hasura for backend and DB
-
Apollo for handling graphql and management state
-
Heroku for deploying Hasura
-
- Hosting for deploying gatsby file
- Authentication for secure access to Hasura DB
- Cloud Functions for handling JWT
- Cloud Firestore for token refresh
-
Create a Gatsby site.
Use the Gatsby CLI to create a new site, specifying this repo.
gatsby new <appname> https://github.com/Zett-8/great-gatsby
-
Start developing.
Navigate into your new site’s directory and start it up.
cd <appname>/ gatsby develop
-
Check on browser
The site is now running at
http://localhost:8000
Note: You'll also see a second link:
http://localhost:8000/___graphql
. This is a tool you can use to experiment with querying your data. Learn more about using this tool in the Gatsby tutorial.
-
Init Firebase project
-- Caution! --
DO NOT overwrite functions/index.jsnpm install -g firebase-tools firebase init firebase deploy
then fill Firebase config
./src/provider/firebase.js
if (!firebase.apps.length) firebase.initializeApp({ apiKey: '', authDomain: '', databaseURL: '', projectId: '', storageBucket: '', messagingSenderId: '', appId: '', })
-
Build postgres DB and Hasura on Heroku
You can easily do this just by clicking the button!
Follow the official document of Hasura
https://hasura.io/ -
Set config on heroku
{ "HASURA_GRAPHQL_ADMIN_SECRET": "<randomString>", "HASURA_GRAPHQL_CORS_DOMAIN": "*", "HASURA_GRAPHQL_UNAUTHORIZED_ROLE": "anonymous", "HASURA_GRAPHQL_JWT_SECRET": { "type": "RS256", "jwk_url": "https://www.googleapis.com/service_accounts/v1/jwk/securetoken@system.gserviceaccount.com", "audience": "<FIREBASE_PROJECT_ID>", "issuer": "https://securetoken.google.com/<FIREBASE_PROJECT_ID>" } }
-
Specify graphql endpoint for Apollo
./src/provider/apolloAuth.js
const client = new ApolloClient({ uri: '<ENDPOINT HERE>', })
then enable Apollo Provider!
./gatsby-wrapper.js
export default ({ element }) => ( <> <ApolloAuthProvider> <CssBaseline /> {element} </ApolloAuthProvider> </> )
-
Set up hasura info
./functions/index.jsconst client = new ApolloClient({ fetch, uri: functions.config().hasura.url, request: (operation) => { operation.setContext({ headers: { 'x-hasura-admin-secret': functions.config().hasura.admin_secret, }, }) }, })
make sure user model or modify
client.mutate({ variables: { id: user.uid, email: user.email || '' }, mutation: gql` mutation InsertUsers($id: String, $email: String) { insert_users(objects: { id: $id, name: $name }) { returning { id name email created_at } } } `, })
A quick look at the top-level files and directories you'll see in a Gatsby project.
.
├── node_modules
├── functions
├── src
├── .gitignore
├── .prettierrc
├── gatsby-browser.js
├── gatsby-config.js
├── gatsby-node.js
├── gatsby-ssr.js
├── gatsby-wrapper.js
├── jest.config.js
├── jest-preprocess.js
├── loadershim.js
├── setup-test-env.js
├── LICENSE
├── package-lock.json
├── package.json
└── README.md
Looking for more guidance? Full documentation for Gatsby lives on the website. Here are some places to start:
-
For most developers, we recommend starting with our in-depth tutorial for creating a site with Gatsby. It starts with zero assumptions about your level of ability and walks through every step of the process.
-
To dive straight into code samples, head to our documentation. In particular, check out the Guides, API Reference, and Advanced Tutorials sections in the sidebar.