Skip to content

Commit 7cd90ce

Browse files
committed
updated documentation
1 parent 01789e5 commit 7cd90ce

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

README.md

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,20 @@
22

33
graphql-codegen-hasura is a collection of code generator plugins for [graphql-code-generator](https://graphql-code-generator.com/). These plugins are designed to automate some coding tasks around the development of a strongly typed [Hasura](https://hasura.io/) backend with an [Apollo GraphQL](https://www.apollographql.com/) React client.
44

5+
## Approaches
6+
7+
These plugins allow for the following approaches to Hasura client code generation (or a combination of both):
8+
9+
1. **Table First**: Generate Hasura client code (gql & TypeScript) for every table defined in Hasura. This approach allows you to get up and running the fastest. However, it may result in a lot of unused (and so unnecessary) code being generated.
10+
11+
2. **Fragment First**: Generate Hasura client code (gql & TypeScript) for every fragment defined in the target source code. This approach approach will generally provide greater long-term flexibility as it allows you to define and work with nested entity graphs. It also will only generate the code you need. However, it is slightly less automated, as it requires you to define graph fragments manually
12+
13+
## The Plugins
14+
515
These plugins require and augment the existing fantastic GraphQL code generator plugins available from [graphql-code-generator](https://graphql-code-generator.com/)
616

717
- The **graphql-codegen-hasura-gql-from-schema** plugin generates [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) gql fragments, mutations and queries for every _Table_ defined in the Hasura database
18+
- The **graphql-codegen-hasura-gql-from-documents** plugin generates [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) gql mutations and queries for every _Fragment_ defined in the targeted (code) documents.
819
- The **graphql-codegen-hasura-typescript-from-schema** plugin generates [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) TypeScript helper methods for every _Table_ defined in the Hasura database.
920
- The **graphql-codegen-hasura-typescript-from-documents** plugin generates [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) TypeScript helper methods for every _Fragment_ defined in the targeted (code) documents.
1021

@@ -39,7 +50,7 @@ It is **important to note**: The TypeScript Generation leverages the files creat
3950
3. Add the graphql-codegen-hasura packages:
4051

4152
```
42-
yarn add graphql-codegen-hasura-gql-from-schema graphql-codegen-hasura-typescript-from-schema graphql-codegen-hasura-typescript-from-documents
53+
yarn add graphql-codegen-hasura-gql-from-schema graphql-codegen-hasura-gql-from-documents graphql-codegen-hasura-typescript-from-schema graphql-codegen-hasura-typescript-from-documents
4354
```
4455

4556
4. Create configuration YAML files (see below)
@@ -66,6 +77,15 @@ See [graphql-code-generator documentation](https://graphql-code-generator.com/do
6677
- withUpdates: boolean flag for update gql code generation
6778
- withDeletes: boolean flag for delete gql code generation
6879

80+
### graphql-codegen-hasura-gql-documents plugin
81+
82+
- reactApolloVersion (2 | 3, default value: 3): sets the version of react-apollo
83+
- typescriptCodegenOutputRelativePath: import path to the code generated with dependent @graphql-codegen/typescript generated code
84+
- withQueries: boolean flag for query TypeScript code generation
85+
- withInserts: boolean flag for insert TypeScript code generation
86+
- withUpdates: boolean flag for update TypeScript code generation
87+
- withDeletes: boolean flag for delete TypeScript code generation
88+
6989
### graphql-codegen-hasura-typescript-schema plugin
7090

7191
- reactApolloVersion (2 | 3, default value: 3): sets the version of react-apollo
@@ -94,7 +114,7 @@ See [graphql-code-generator documentation](https://graphql-code-generator.com/do
94114

95115
Generates gql fragments, mutations and queries for every _Table_ defined in the Hasura database.
96116

97-
See [demo/src/autogen/hasura/gql.ts](https://github.com/ahrnee/graphql-codegen-hasura/tree/master/demo/src/autogen/hasura) for generated output files.
117+
See [demo/src/autogen/hasura/gql-from-schema.ts](https://github.com/ahrnee/graphql-codegen-hasura/tree/master/demo/src/autogen/hasura) for generated output files.
98118

99119
#### Example Output for `User` Entity
100120

@@ -207,6 +227,18 @@ const REMOVE_USERS_MODELS = gql`
207227
`;
208228
```
209229

230+
### graphql-codegen-hasura-gql-from-documents plugin
231+
232+
#### Overview
233+
234+
Generates [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) gql mutations and queries for every _Fragment_ defined in the targeted (code) documents.
235+
236+
See [demo/src/autogen/hasura/gql-from-documents.ts](https://github.com/ahrnee/graphql-codegen-hasura/tree/master/demo/src/autogen/hasura) for generated output files.
237+
238+
#### Example Output
239+
240+
This has the same output as the [graphql-codegen-hasura-typescript-from-schema](#graphql-codegen-hasura-typescript-from-schema-plugin) plugin, except that the generated code is fragment-driven, as opposed to table-driven
241+
210242
### graphql-codegen-hasura-typescript-from-schema plugin
211243

212244
#### Overview
@@ -215,7 +247,7 @@ Generates [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete)
215247

216248
The existing [@graphql-codegen/typescript-react-apollo](https://graphql-code-generator.com/docs/plugins/typescript-react-apollo) plugin already provides this capability for hooks. This plugin extends that to direct client.query & client.mutate calls, in addition to adding some convenience features.
217249

218-
See [demo/src/autogen/hasura/typescript.ts](https://github.com/ahrnee/graphql-codegen-hasura/tree/master/demo/src/autogen/hasura) for generated output files.
250+
See [demo/src/autogen/hasura/typescript-from-schema.ts](https://github.com/ahrnee/graphql-codegen-hasura/tree/master/demo/src/autogen/hasura) for generated output files.
219251

220252
#### Example Output for `User` Entity
221253

@@ -325,11 +357,11 @@ Generates [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete)
325357

326358
The existing [@graphql-codegen/typescript-react-apollo](https://graphql-code-generator.com/docs/plugins/typescript-react-apollo) plugin already provides this capability for hooks. This plugin extends that to direct client.query & client.mutate calls, in addition to adding some convenience features.
327359

328-
See [demo/src/autogen/hasura/typescript.ts](https://github.com/ahrnee/graphql-codegen-hasura/tree/master/demo/src/autogen/hasura) for generated output files.
360+
See [demo/src/autogen/hasura/typescript-from-documents.ts](https://github.com/ahrnee/graphql-codegen-hasura/tree/master/demo/src/autogen/hasura) for generated output files.
329361

330-
#### Example Output for `User` Entity
362+
#### Example Output
331363

332-
This has the same output as the [graphql-codegen-hasura-typescript-from-documents](#graphql-codegen-hasura-typescript-from-schema-plugin) plugin
364+
This has the same output as the [graphql-codegen-hasura-typescript-from-schema](#graphql-codegen-hasura-typescript-from-schema-plugin) plugin, except that the generated code is fragment-driven, as opposed to table-driven
333365

334366
## Naming Conventions
335367

0 commit comments

Comments
 (0)