Skip to content
This repository was archived by the owner on Oct 31, 2024. It is now read-only.

Commit 0320332

Browse files
authored
Update README.md
1 parent dfad862 commit 0320332

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

README.md

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ https://reactql.org
1313

1414
- [React v16](https://facebook.github.io/react/) for UI.
1515
- [Apollo Client 2.0 (React)](http://dev.apollodata.com/react/) for connecting to GraphQL.
16-
- [MobX](https://mobx.js.org/) for declarative, type-safe flux/store state management (automatically re-hydrated from the server.)
16+
- [MobX](https://mobx.js.org/) for declarative, type-safe flux/store state management (automatically re-hydrated from the server.) which is auto-saved and reloaded to `localStorage` in the client (simple to disable if you don't need it.)
1717
- [Emotion](https://emotion.sh/) CSS-in-JS, with inline `<style>` tag generation that contains only the CSS that needs to be rendered.
1818
- [Sass](https://sass-lang.com/), [Less](http://lesscss.org/) and [PostCSS](https://postcss.org/) when importing `.css/.scss/.less` files.
1919
- [React Router 4](https://reacttraining.com/react-router/) for declarative browser + server routes.
20-
20+
- [GraphQL Code Generator](https://graphql-code-generator.com/) for parsing remote GraphQL server schemas, for automatically building fully-typed Apollo React HOCs instead of writing `<Query>` / `<Mutation>` queries manually
2121
- Declarative/dynamic `<head>` section, using [react-helmet](https://github.com/nfl/react-helmet).
2222

2323
### Server-side rendering
@@ -70,14 +70,45 @@ https://reactql.org
7070
Grab and unpack the latest version, install all dependencies, and start a server:
7171

7272
```
73-
wget -qO- https://github.com/leebenson/reactql/archive/4.2.0.tar.gz | tar xvz
74-
cd reactql-4.2.0
73+
wget -qO- https://github.com/leebenson/reactql/archive/4.2.1.tar.gz | tar xvz
74+
cd reactql-4.2.1
7575
npm i
7676
npm start
7777
```
7878

7979
Your development server is now running on [http://localhost:3000](http://localhost:3000)
8080

81+
## Building GraphQL HOCs
82+
83+
By default, your GraphQL schema lives in [schema/schema.graphql](schema/schema.graphql)
84+
85+
To create fully Typescript-typed Apollo React HOCs based on your schema, simply put the query in a `.graphql` anywhere inside the source folder, and run:
86+
87+
```
88+
npm run gen:graphql
89+
```
90+
91+
You can then import the query like we do in the [HackerNews demo component](src/components/example/hackernews.tsx):
92+
93+
```ts
94+
// Query to get top stories from HackerNews
95+
import { GetHackerNewsTopStories } from "@/graphql";
96+
```
97+
98+
And use it as follows:
99+
100+
```ts
101+
<GetHackerNewsTopStories.Component>
102+
{({ data, loading, error }) => (...)
103+
</GetHackerNewsTopStories.Component>
104+
```
105+
106+
To get access to the underlying `gql`-templated query (in case you need it for refetching, etc), in this case it'd be `GetHackerNewsTopStories.Document`.
107+
108+
See [GraphQL Code Generator](https://graphql-code-generator.com/) for more details on how it works.
109+
110+
You can also edit [codegen.yml](codegen.yml) in the root to point to a remote schema, or change the file location.
111+
81112
## Development mode
82113
83114
Development mode offers a few useful features:
@@ -203,10 +234,12 @@ Here's a quick run-through of each sub-folder and what you'll find in it:
203234
204235
You'll also find some other useful goodies in the [root]()...
205236
206-
- [.env](.env) - Change your `GRAPHQL` server endpoint, and `WS_SUBSCRIPTIONS=1` for built-in WebSocket support.
237+
- [.env](.env) - Change your `GRAPHQL` server endpoint, `WS_SUBSCRIPTIONS=1` for built-in WebSocket support, `HOST` if you want to bind the server to something other than localhost, and `LOCAL_STORAGE_KEY` to set the root key for saving MobX state locally in the client for automatic re-loading in a later session.
207238
208239
- [.nvmrc](.nvmrc) - Specify your preferred Node.js version, for use with NVM and used by many continuous deployment tools. Defaults to v11.8.0
209240
241+
- [codegen.yml](codegen.yml) - Settings for [GraphQL Code Generator](https://graphql-code-generator.com/) (which you can run with `npm run gen:graphql` to generate types/HOCs based on your GraphQL queries/mutations.)
242+
210243
- [netlify.toml](netlify.toml) - Build instructions for fast [Netlify](https://www.netlify.com/) deployments. **Tip: To quickly deploy a demo ReactQL app, [click here](https://app.netlify.com/start/deploy?repository=https://github.com/leebenson/reactql).**
211244
212245
- [types](types) - Some basic types that allow you to import fonts, images, CSS/SASS/LESS files, and allow use of the global `SERVER` boolean in your IDE.

0 commit comments

Comments
 (0)