|
1 | 1 | <p align="center"><img src="https://imgur.com/c6Y4tGw.png" width="150" /></p> |
2 | 2 |
|
3 | | -# graphqlgen |
| 3 | +# graphqlgen <!-- omit in toc --> |
4 | 4 |
|
5 | 5 | [](https://circleci.com/gh/prisma/graphqlgen) [](https://badge.fury.io/js/graphqlgen) |
6 | 6 |
|
7 | | -> Generate & scaffold type-safe resolvers based on your GraphQL Schema in TypeScript, Flow & Reason |
| 7 | +Generate & scaffold type-safe resolvers based on your GraphQL Schema in TypeScript, Flow & Reason |
8 | 8 |
|
9 | | -## Features |
| 9 | +- [About](#about) |
| 10 | + - [Highlights](#highlights) |
| 11 | + - [Motivation](#motivation) |
| 12 | + - [Supported languages](#supported-languages) |
| 13 | +- [Getting started](#getting-started) |
| 14 | + - [Try out a project initializer](#try-out-a-project-initializer) |
| 15 | + - [Add to existing project](#add-to-existing-project) |
| 16 | + - [Documentation](#documentation) |
| 17 | +- [Addendum](#addendum) |
| 18 | + - [Community](#community) |
| 19 | + - [Project Status](#project-status) |
| 20 | + - [Prior Art](#prior-art) |
10 | 21 |
|
11 | | -- **🚀 Schema-first:** Based on your GraphQL schema (SDL) & model definitions |
12 | | -- **🤝 Type-safe:** Strong mapping between your GraphQL schema and resolvers, input arguments and models |
13 | | -- **♻️ Codegen & scaffolding workflows:** Minimal resolver boilerplate & automatically generated type definitions |
14 | | -- **😍 Awesome DX:** Auto-completion & Intellisense in VSCode, Webstorm, Atom, VIM & other editors |
15 | | -- **💅 Ecosystem compatibility:** Supports [prettier](https://github.com/prettier/prettier) and [graphql-import](https://github.com/prisma/graphql-import) out of the box |
| 22 | +## About |
16 | 23 |
|
17 | | -## Documentation |
| 24 | +### Highlights |
18 | 25 |
|
19 | | -You can find the docs for the `graphqlgen` CLI [here](https://oss.prisma.io/graphqlgen/). |
| 26 | +- **Schema-first** Design in SDL to derive ideal types |
| 27 | +- **Type-safety** Resolvers with precise signatures including `parent`, `args` and return type |
| 28 | +- **DX** Precise resolver types puts your editor intellisense to work |
| 29 | +- **Ecosystem Interop** codegen suitable for Yoga 1 or Apollo Server and supports [prettier](https://github.com/prettier/prettier) and [graphql-import](https://github.com/prisma/graphql-import) out of the box |
20 | 30 |
|
21 | | -## Motivation |
| 31 | +### Motivation |
22 | 32 |
|
23 | | -Programming in type-safe environments provides a lot of benefits and gives you confidence about your code. `graphqlgen` leverages the strongly typed GraphQL schema with the goal of making your backend type-safe while reducing the need to write boilerplate through code generation. |
| 33 | +Programming in type-safe environments can contribute toward great confidence in your code's integrity. `graphqlgen` aims to leverage the GraphQL type system to make your resolvers completely type-safe. This is important because resolvers are the heart of any graphql service and yet the hardest to statically type due to their dynaminism. |
24 | 34 |
|
25 | | -#### Supported languages: |
| 35 | +### Supported languages |
26 | 36 |
|
27 | 37 | - `TypeScript` |
28 | 38 | - `Flow` |
29 | | -- `Reason` ([coming soon](https://github.com/prisma/graphqlgen/issues/253)) |
30 | 39 |
|
31 | | -## Get started |
| 40 | +Others under discussion: |
32 | 41 |
|
33 | | -### Start from scratch |
| 42 | +- [`reason`](https://github.com/prisma/graphqlgen/issues/253) |
34 | 43 |
|
35 | | -Bootstrap a GraphQL server based with a ready-made `graphqlgen` setup then |
36 | | -start the server: |
| 44 | +## Getting started |
37 | 45 |
|
38 | | -_With `npm`_ |
| 46 | +### Try out a project initializer |
39 | 47 |
|
40 | | -```bash |
41 | | -npm init graphqlgen my-app |
42 | | -cd my-app |
43 | | -npm start |
44 | | -``` |
45 | | - |
46 | | -_Note: `npm init` requires npm version >= 6.2.0_ |
47 | | - |
48 | | -or |
| 48 | +1. Run initializer |
49 | 49 |
|
50 | | -_With `yarn`_ |
51 | | - |
52 | | -```bash |
53 | | -yarn create graphqlgen my-app |
54 | | -cd my-app |
55 | | -yarn start |
56 | | -``` |
| 50 | + ```bash |
| 51 | + yarn create graphqlgen my-app # npm init graphqlgen my-app |
| 52 | + cd my-app |
| 53 | + yarn start # npm run start |
| 54 | + ``` |
57 | 55 |
|
58 | | -_Note: `yarn create` requires yarn version >= 0.25_ |
| 56 | +2. Edit `./my-app/src/schema.graphql` to your heart's content. |
59 | 57 |
|
60 | | -After updating the GraphQL schema in `./my-app/src/schema.graphql`, execute the `graphqlgen` CLI to update all resolvers: |
| 58 | +3. Generate types: |
61 | 59 |
|
62 | | -``` |
63 | | -graphqlgen |
64 | | -``` |
| 60 | + ``` |
| 61 | + yarn graphqlgen |
| 62 | + ``` |
65 | 63 |
|
66 | 64 | ### Add to existing project |
67 | 65 |
|
68 | | -#### Install |
69 | | - |
70 | | -You can install the `graphqlgen` CLI with either of the following commands: |
71 | | - |
72 | 66 | ```bash |
73 | | -npm install -g graphqlgen |
| 67 | +yarn add --dev graphqlgen # npm install --save-dev graphqlgen |
74 | 68 | ``` |
75 | 69 |
|
76 | | -or |
| 70 | +Then you will have access to the cli (`gg` or `graphqlgen`): |
77 | 71 |
|
78 | 72 | ```bash |
79 | | -yarn global add graphqlgen |
| 73 | +yarn -s gg --help # npm run gg --help |
80 | 74 | ``` |
81 | 75 |
|
82 | | -#### Usage |
83 | | - |
84 | | -Once installed, you can invoke the CLI as follows: |
85 | | - |
86 | 76 | ``` |
87 | | -graphqlgen |
| 77 | +Usage: graphqlgen or gg |
| 78 | +
|
| 79 | +Options: |
| 80 | + -i, --init Initialize a graphqlgen.yml file |
| 81 | + -v, --version Show version number [boolean] |
| 82 | + -h, --help Show help [boolean] |
88 | 83 | ``` |
89 | 84 |
|
90 | | -The invocation of the command depends on a configuration file called `graphqlgen.yml` which **must be located in the directory where `graphqlgen` is invoked**. Here is an example: |
| 85 | +`gg` depends on the presence of a `graphqlgen.yml` config **located in the directory where `gg` is invoked**. Here is an example: |
91 | 86 |
|
92 | 87 | ```yml |
93 | 88 | language: typescript |
94 | | - |
95 | 89 | schema: ./src/schema.graphql |
96 | | -context: ./src/types.ts:Context |
| 90 | +context: ./src/context.ts:Context |
| 91 | +output: ./src/generated/graphqlgen.ts |
97 | 92 | models: |
98 | 93 | files: |
99 | 94 | - ./src/generated/prisma-client/index.ts |
100 | | - |
101 | | -output: ./src/generated/graphqlgen.ts |
102 | | - |
103 | | -resolver-scaffolding: |
104 | | - output: ./src/generated/tmp-resolvers/ |
105 | | - layout: file-per-type |
106 | | -``` |
107 | | -
|
108 | | -Learn more about the configuration in the [docs](https://oss.prisma.io/graphqlgen/01-configuration.html). |
109 | | -
|
110 | | -## Support |
111 | | -
|
112 | | -- [Create a feature request](https://github.com/prisma/graphqlgen/issues/new?template=feature_request.md&labels=enhancement) |
113 | | -- [Create a bug report](https://github.com/prisma/graphqlgen/issues/new?template=bug_report.md&labels=bug) |
114 | | -
|
115 | | -<Details><Summary><b>Note: Using <code>graphqlgen</code> in production</b></Summary> |
116 | | -<br /> |
117 | | -
|
118 | | -While `graphqlgen` is ready to be used in production, it's still in active development and there might be breaking changes before it hits 1.0. Most changes will just affect the configuration and generated code layout but not the behaviour of the code itself. |
119 | | - |
120 | | -</Details> |
121 | | - |
122 | | -## Help & Community |
123 | | - |
124 | | -[](https://slack.prisma.io) |
125 | | - |
126 | | -Join the `#graphqlgen` channel our [Slack community](http://slack.graph.cool/) if you run into issues or have questions. We love talking to you! |
127 | | - |
128 | | -## Benchmarks |
129 | | - |
130 | | -Benchmarks exist for the graphqlgen package. |
131 | | - |
132 | | -- Results can be reviewed in [history.json](https://github.com/prisma/graphqlgen/blob/master/packages/graphqlgen/benchmarks/history.json) |
133 | | -- Run benchmarks within that package via `yarn run benchmarks` |
134 | | -- Save results via `yarn run benchmarks --save` |
135 | | - |
136 | | -### Folder Structure |
137 | | - |
138 | | -``` |
139 | | -/benchmarks |
140 | | - history.json <-- file keeping results of past benchmark runs |
141 | | - index.ts <-- benchmark execution entrypoint |
142 | | - /lib/* <-- base tools/types/logic for benchmark system |
143 | | - /integration <-- integration-type benchmarks testing how quickly code-generation runs |
144 | | - index.ts <-- integration-type benchmarks entrypoint (creates & collects benchmarks) |
145 | | - /a <-- integration-type benchmark for a particular set of fixtures |
146 | | - model.ts |
147 | | - schema.graphql |
148 | | - /b/* |
149 | | - /c/* |
150 | 95 | ``` |
151 | 96 |
|
152 | | -### Developer Guide |
153 | | -
|
154 | | -#### Adding a new integration-type benchmark |
155 | | -
|
156 | | -1. Create a new folder for your benchmark case: |
157 | | -
|
158 | | - ``` |
159 | | - /benchmarks |
160 | | - /integration |
161 | | - /<YOUR-BENCHMARK-TITLE-HERE> |
162 | | - ``` |
163 | | -
|
164 | | -2. Add fixtures containing whatever data case/pattern you're interested in benching: |
165 | | -
|
166 | | - ``` |
167 | | - model.ts |
168 | | - schema.graphql |
169 | | - ``` |
| 97 | +### Documentation |
170 | 98 |
|
171 | | -#### Adding a new type of benchmark |
| 99 | +https://oss.prisma.io/graphqlgen |
172 | 100 |
|
173 | | -1. Create a new folder for your benchmark type: |
174 | | -
|
175 | | - ``` |
176 | | - /benchmarks |
177 | | - /<YOUR-BENCHMARK-TYPE-TITLE-HERE> |
178 | | - ``` |
| 101 | +## Addendum |
179 | 102 |
|
180 | | -2. Implement an `index.ts` that exports a `collect` function: |
| 103 | +### Community |
181 | 104 |
|
182 | | - ``` |
183 | | - /benchmarks |
184 | | - /<YOUR-BENCHMARK-TYPE-TITLE-HERE> |
185 | | - index.ts |
186 | | - ``` |
| 105 | +Join us at `#graphqlgen` in our [Slack group](https://slack.prisma.io) and if you have more fleshed out ideas, bug reports etc. create a Github issue: |
187 | 106 |
|
188 | | - ```ts |
189 | | - import * as Benchmark from '../lib/benchmark' |
| 107 | +- [feature request](https://github.com/prisma/graphqlgen/issues/new?template=feature_request.md&labels=enhancement) |
| 108 | +- [bug report](https://github.com/prisma/graphqlgen/issues/new?template=bug_report.md&labels=bug) |
190 | 109 |
|
191 | | - const collect: Benchmark.Collect = () => { |
192 | | - // TODO |
193 | | - } |
| 110 | +### Project Status |
194 | 111 |
|
195 | | - export { collect } |
196 | | - ``` |
197 | | - |
198 | | - The collect function is responsible for returning benchmarks from your benchmark type to run. Some guidelines to keep in mind: |
199 | | - |
200 | | - 1. Adding new benchmarks to this type should be trivial, therefore, should only require the addition of fixtures and/or benchmark-specific code. For example the benchmark type should be prepared to pick up new folders automatically. |
201 | | - |
202 | | - 2. Support all types of languages supported by graphqlgen |
203 | | - |
204 | | - With your system in place, add benchmarks as needed, in the format your collector dictates: |
205 | | - |
206 | | - ``` |
207 | | - /benchmarks |
208 | | - /<YOUR-BENCHMARK-TYPE-TITLE-HERE> |
209 | | - index.ts |
210 | | - ... <-- dictated by your collector |
211 | | - ``` |
| 112 | +`graphqlgen` is still in early stage development where breaking changes and tool design are a fluid matter. Feedback is deeply appreciated. You may feel comfortable giving it a try on production systems since there is no runtime aspect and hence quite safe to do so (save for a few optional default resolvers). |
212 | 113 |
|
213 | | -## Prior Art |
| 114 | +### Prior Art |
214 | 115 |
|
215 | 116 | - [**gqlgen**](https://github.com/99designs/gqlgen) is the Golang equivalent of `graphqlgen` and served as a source of inspiration |
216 | 117 | - [**graphql-code-generator**](https://github.com/dotansimha/graphql-code-generator) is a similar tool based on templates support both frontend & backend |
|
0 commit comments