|
1 |
| -# Build a blog powered by GitHub issues |
| 1 | +This repo powers the [OneGraph changelog](https://onegraph.com/changelog). All of the entries in the changelog are issues in this repo. |
2 | 2 |
|
3 |
| -[](https://vercel.com/new/git/external?repository-url=https%3A%2F%2Fgithub.com%2FOneGraph%2Foneblog%2Ftree%2Fnext&env=NEXT_PUBLIC_ONEGRAPH_APP_ID,NEXT_PUBLIC_TITLE,OG_GITHUB_TOKEN,OG_DASHBOARD_ACCESS_TOKEN,VERCEL_URL,VERCEL_GITHUB_ORG,VERCEL_GITHUB_REPO&envDescription=Variables%20needed%20to%20build%20your%20OneBlog&envLink=https%3A%2F%2Fgithub.com%2FOneGraph%2Foneblog%2Ftree%2Fnext%23environment-variables&project-name=oneblog&repo-name=oneblog) |
| 3 | +See the [https://onegraph.com/oneblog](https://onegraph.com/oneblog) for how to deploy your own changelog backed by GitHub issues. |
4 | 4 |
|
5 |
| -This repo allows you to generate a blog from GitHub issues on a repo. It powers the [OneGraph Product Updates blog](https://www.onegraph.com/changelog), [Stepan Parunashvili's blog](https://stopa.io/), [bdougie.live](https://www.bdougie.live/), and more. |
| 5 | +### Developing on this repo |
6 | 6 |
|
7 |
| -All of the posts are stored as issues on the repo (e.g. [OneGraph/onegraph-changelog](https://github.com/OneGraph/onegraph-changelog/issues?utf8=%E2%9C%93&q=is%3Aissue+label%3Apublish+)). |
| 7 | +What follows are implementation details specific to this repo. For setting up a general oneblog, see [https://github.com/oneblog](https://github.com/oneblog). |
8 | 8 |
|
9 |
| -When you visit the page at [onegraph.com/changelog](https://www.onegraph.com/changelog), a GraphQL query fetches the issues from GitHub via OneGraph's persisted queries and renders them as blog posts. |
| 9 | +Staging triggers a build on [staging cloudbuild](https://console.cloud.google.com/cloud-build/builds?project=sourcecodeshots) on every push to non-master and deploys to staging firebase hosting/cloud run. |
10 | 10 |
|
11 |
| -The persisted queries are stored with authentication credentials for GitHub that allows them to make authenticated requests. Persisting the queries locks them down so that they can't be made to send arbitrary requests to GitHub. |
| 11 | +Production triggers a build on (https://console.cloud.google.com/cloud-build/builds?project=onegraph-prod) on pushes to master and deploys to prod firebase hosting/cloud run. |
12 | 12 |
|
13 |
| -You can learn more about [persisted queries in the docs](https://www.onegraph.com/docs/persisted_queries.html). |
14 |
| - |
15 |
| -## Setup |
16 |
| - |
17 |
| -Use an existing OneGraph app or sign up sign up at [OneGraph](https://www.onegraph.com) to create a new app. |
18 |
| - |
19 |
| -Copy `/.env.example` to `/.env` and set the following environment variables. |
20 |
| - |
21 |
| -### Environment variables |
22 |
| - |
23 |
| -| Environment Variable | Description | |
24 |
| -| ------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
25 |
| -| `OG_GITHUB_TOKEN` | A server-side access token created on OneGraph, used as the default auth for the persisted queries that will fetch the issues. To create a new one, go the "Server-side Auth" tab in the [OneGraph dashboard](https://www.onegraph.com/dashboard) for your app, click the "Create Token" button, and add GitHub to the services. Keep this token safe, because it has access to your GitHub data. | |
26 |
| -| `OG_DASHBOARD_ACCESS_TOKEN` | An API token that allows you to create persisted queries on OneGraph. Go to the "Persisted queries" tab on the OneGraph dashboard, scroll down, and click "Create token". This will create a scoped token for your app that can create persisted queries on your behalf. | |
27 |
| -| `NEXT_PUBLIC_ONEGRAPH_APP_ID` | The id of your OneGraph app. You can get this from the [OneGraph dashboard](https://www.onegraph.com/dashboard) | |
28 |
| -| `NEXT_PUBLIC_TITLE` | The title of your site | |
29 |
| -| `NEXT_PUBLIC_DESCRIPTION` | A short description of your site. | |
30 |
| -| `NEXT_PUBLIC_GITHUB_REPO_OWNER` | The owner of the repo that we should pull issues from (e.g. linus in linus/oneblog). If you're using the Vercel deploy button, you don't need to provide this. | |
31 |
| -| `NEXT_PUBLIC_GITHUB_REPO_NAME` | The name of the repo that we should pull issues from (e.g. oneblog in linus/oneblog). If you're using the Vercel deploy button, you don't need to provide this. | |
32 |
| - |
33 |
| -### Setup relay |
34 |
| - |
35 |
| -Remove the generated files (they're tied to the OneGraph app they were generated with): |
36 |
| - |
37 |
| -``` |
38 |
| -yarn relay:clean |
39 |
| -# which runs rm -r src/__generated__ |
40 |
| -``` |
41 |
| - |
42 |
| -(Note: any time you change the variables in `.env`, it's a good idea to stop the relay compiler, remove the files in `src/__generated__`, and restart the compiler) |
43 |
| - |
44 |
| -Install dependencies |
45 |
| - |
46 |
| -``` |
47 |
| -yarn install |
48 |
| -``` |
49 |
| - |
50 |
| -### Run the Relay compiler |
51 |
| - |
52 |
| -This project uses Relay as its GraphQL client because of its high-quality compiler and great support for persisted queries. |
53 |
| - |
54 |
| -In another terminal window, start the relay compiler |
55 |
| - |
56 |
| -``` |
57 |
| -yarn relay --watch |
58 |
| -``` |
59 |
| - |
60 |
| -You may need to install [watchman](https://facebook.github.io/watchman/), a file watching service. On mac, do `brew install watchman`. On Windows or Linux, follow the instructions at [https://facebook.github.io/watchman/docs/install.html](https://facebook.github.io/watchman/docs/install.html). |
61 |
| - |
62 |
| -### Start the server |
63 |
| - |
64 |
| -Now that we've generated the relay files, we can start the server. |
65 |
| - |
66 |
| -``` |
67 |
| -yarn start |
68 |
| -``` |
69 |
| - |
70 |
| -The project will load at [http://localhost:3000](http://localhost:3000). |
71 |
| - |
72 |
| -## Deploying |
73 |
| - |
74 |
| -The project comes with setups for deploying to Google's Firebase, Zeit's Now, Netlify, and Fly.io. |
75 |
| - |
76 |
| -For each of these, you'll have to add the site that you're deploying to on the CORS origins on the OneGraph dashboard. |
77 |
| - |
78 |
| -### Deploy with Vercel |
79 |
| - |
80 |
| -Use the deploy button to set up a new repo: |
81 |
| - |
82 |
| -[](https://vercel.com/new/git/external?repository-url=https%3A%2F%2Fgithub.com%2FOneGraph%2Foneblog%2Ftree%2Fnext&env=NEXT_PUBLIC_ONEGRAPH_APP_ID,NEXT_PUBLIC_TITLE,OG_GITHUB_TOKEN,OG_DASHBOARD_ACCESS_TOKEN,VERCEL_URL,VERCEL_GITHUB_ORG,VERCEL_GITHUB_REPO&envDescription=Variables%20needed%20to%20build%20your%20OneBlog&envLink=https%3A%2F%2Fgithub.com%2FOneGraph%2Foneblog%2Ftree%2Fnext%23environment-variables&project-name=oneblog&repo-name=oneblog) |
83 |
| - |
84 |
| -If you've already set up the repo, just run the vercel command. |
85 |
| - |
86 |
| -``` |
87 |
| -# If not installed |
88 |
| -# npm i -g vercel |
89 |
| -
|
90 |
| -vercel |
91 |
| -``` |
92 |
| - |
93 |
| -If you see an error when you visit the site, make sure the site's origin is listed in the CORS origins for your app on the OneGraph dashboard. |
94 |
| - |
95 |
| -### Deploying with Firebase |
96 |
| - |
97 |
| -Please open an issue if you'd like help deploying with Firebase. |
98 |
| - |
99 |
| -### Deploying with Netlify |
100 |
| - |
101 |
| -Please open an issue if you'd like help deploying with Netlify. |
102 |
| - |
103 |
| -### Deploying with Fly.io |
104 |
| - |
105 |
| -Please open an issue if you'd like help deploying with Fly.io |
106 |
| - |
107 |
| -## Project setup |
108 |
| - |
109 |
| -### Client |
110 |
| - |
111 |
| -The client is an ordinary React app. The best to place to start is `/src/App.js`. |
112 |
| - |
113 |
| -It uses Grommet as the UI library. Visit [https://v2.grommet.io/components](https://v2.grommet.io/components) to view the documentation for Grommet. |
114 |
| - |
115 |
| -It uses Relay as the GraphQL client. [https://relay.dev/docs/en/graphql-in-relay](https://relay.dev/docs/en/graphql-in-relay) has a good introduction to Relay. |
116 |
| - |
117 |
| -To refresh the GraphQL schema, run `yarn fetch-schema`. That will fetch the schema from OneGraph and add some client-only directives that we use when we persist the queries to OneGraph. |
118 |
| - |
119 |
| -#### How persisting works |
120 |
| - |
121 |
| -The `persistFunction` for the relay compiler is set to `/scripts/persistQuery.js`. Every time a GraphQL query in the project changes, the relay compiler will call that function with the new query. |
122 |
| - |
123 |
| -That function will parse the query and pull out the `@persistedQueryConfiguration` directive to determine if any auth should be stored alongside the query. In the changelog, the queries for fetching posts use persisted auth, but the mutations for adding reactions require the user to log in with OneGraph and use their auth. |
124 |
| - |
125 |
| -The `@persistedQueryConfiguration` directive is stripped from the query and it is uploaded to OneGraph via a GraphQL mutation. Then the id for the persisted query is returned from the function. Relay stores the id in its generated file and it's used the next time the query is sent to the server. |
126 |
| - |
127 |
| -### Server |
128 |
| - |
129 |
| -The server uses [Next.js](https://nextjs.org) to allow us to render the content on the server. This helps with SEO and allows people to view the blog with Javascript turned off. |
130 |
| - |
131 |
| -When a request comes in to the server, the server creates a mock Relay environment and prefetches the query for the route using `fetchQuery` from `relay-runtime`. This populates the record source that Relay uses to render. |
132 |
| - |
133 |
| -React renders the app to a string, which is sent to the client. |
134 |
| - |
135 |
| -On the client, React rehydates the app. To prevent Relay from showing a loading state, we inject the serialized record source with `getStaticProps`. That data is stored in the environment before Relay makes its first query. The `fetchPolicy` opt is set to "store-and-network" so that it uses the data from the store instead of showing a loading state. |
| 13 | +Check the cloudbuild-staging.yaml, cloudbuild.yaml, and Dockerfile for implementation details. |
0 commit comments