Skip to content

Commit d2e1b81

Browse files
committed
docs(readme): tune up the sections for 1.0.0 release
1 parent 700a343 commit d2e1b81

File tree

1 file changed

+45
-44
lines changed

1 file changed

+45
-44
lines changed

README.md

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,9 @@ Create GraphQL schema and resolvers with TypeScript, using classes and decorator
1616
<br>
1717
[![](https://opencollective.com/typegraphql/donate/button.png?color=white)](https://opencollective.com/typegraphql)
1818

19-
## Motivation
20-
21-
We all know that GraphQL is great and solves many problems we have with REST APIs, like overfetching and underfetching. But developing a GraphQL API in Node.js with TypeScript is sometimes a bit of a pain. Why? Let's take a look at the steps we usually have to take.
22-
23-
First, we create all the GraphQL types in `schema.gql` using SDL. Then we create our data models using [ORM classes](https://github.com/typeorm/typeorm), which represent our db entities. Then we start to write resolvers for our queries, mutations and fields, but this forces us to first create TS interfaces for all arguments, inputs, and even object types.
24-
25-
Only then can we actually implement the resolvers using weird generic signatures and manually performing common tasks, like validation, authorization and loading dependencies:
26-
27-
```ts
28-
export const getRecipesResolver: GraphQLFieldResolver<void, Context, GetRecipesArgs> =
29-
async (_, args, ctx) => {
30-
// common tasks repeatable for almost every resolver
31-
const repository = TypeORM.getRepository(Recipe);
32-
const auth = Container.get(AuthService);
33-
await joi.validate(getRecipesSchema, args);
34-
if (!auth.check(ctx.user)) {
35-
throw new NotAuthorizedError();
36-
}
37-
38-
// our business logic, e.g.:
39-
return repository.find({ skip: args.offset, take: args.limit });
40-
};
41-
```
42-
43-
The biggest problem is redundancy in our codebase, which makes it difficult to keep things in sync. To add a new field to our entity, we have to jump through all the files - modify an entity class, the schema, as well as the interface. The same goes for inputs or arguments. It's easy to forget to update one piece or make a mistake with a single type. Also, what if we've made a typo in field name? The rename feature (F2) won't work correctly.
44-
45-
Tools like [GraphQL Code Generator](https://github.com/dotansimha/graphql-code-generator) or [graphqlgen](https://github.com/prisma/graphqlgen) only solve the first part - they generate the corresponding interfaces (and resolvers skeletons) for our GraphQL schema but they don't fix the schema <--> models redundancy and developer experience (F2 rename won't work, you have to remember about the codegen watch task in background, etc.), as well as common tasks like validation, authorization, etc.
46-
47-
**TypeGraphQL** comes to address these issues, based on experience from a few years of developing GraphQL APIs in TypeScript. The main idea is to have only one source of truth by defining the schema using classes and some help from decorators. Additional features like dependency injection, validation and auth guards help with common tasks that normally we would have to handle ourselves.
48-
4919
## Introduction
5020

51-
As mentioned, **TypeGraphQL** makes developing GraphQL APIs an enjoyable process, i.e. by defining the schema using only classes and a bit of decorator magic.
21+
**TypeGraphQL** makes developing GraphQL APIs an enjoyable process, i.e. by defining the schema using only classes and a bit of decorator magic.
5222

5323
So, to create types like object type or input type, we use a kind of DTO classes.
5424
For example, to declare `Recipe` type we simply create a class and annotate it with decorators:
@@ -119,33 +89,61 @@ type Mutation {
11989
}
12090
```
12191

122-
## Getting started
92+
## Motivation
12393

124-
A full getting started guide with a simple walkthrough (tutorial) can be found at [getting started docs](https://typegraphql.com/docs/getting-started.html).
94+
We all know that GraphQL is great and solves many problems we have with REST APIs, like overfetching and underfetching. But developing a GraphQL API in Node.js with TypeScript is sometimes a bit of a pain. Why? Let's take a look at the steps we usually have to take.
12595

126-
## Video tutorial
96+
First, we create all the GraphQL types in `schema.gql` using SDL. Then we create our data models using [ORM classes](https://github.com/typeorm/typeorm), which represent our db entities. Then we start to write resolvers for our queries, mutations and fields, but this forces us to first create TS interfaces for all arguments, inputs, and even object types.
12797

128-
If you prefer video tutorials, you can watch [Ben Awad](https://github.com/benawad)'s [TypeGraphQL video series](https://www.youtube.com/playlist?list=PLN3n1USn4xlma1bBu3Tloe4NyYn9Ko8Gs) on YouTube.
98+
Only then can we actually implement the resolvers using weird generic signatures and manually performing common tasks, like validation, authorization and loading dependencies:
99+
100+
```ts
101+
export const getRecipesResolver: GraphQLFieldResolver<void, Context, GetRecipesArgs> =
102+
async (_, args, ctx) => {
103+
// common tasks repeatable for almost every resolver
104+
const repository = TypeORM.getRepository(Recipe);
105+
const auth = Container.get(AuthService);
106+
await joi.validate(getRecipesSchema, args);
107+
if (!auth.check(ctx.user)) {
108+
throw new NotAuthorizedError();
109+
}
110+
111+
// our business logic, e.g.:
112+
return repository.find({ skip: args.offset, take: args.limit });
113+
};
114+
```
115+
116+
The biggest problem is redundancy in our codebase, which makes it difficult to keep things in sync. To add a new field to our entity, we have to jump through all the files - modify an entity class, the schema, as well as the interface. The same goes for inputs or arguments. It's easy to forget to update one piece or make a mistake with a single type. Also, what if we've made a typo in field name? The rename feature (F2) won't work correctly.
117+
118+
Tools like [GraphQL Code Generator](https://github.com/dotansimha/graphql-code-generator) or [graphqlgen](https://github.com/prisma/graphqlgen) only solve the first part - they generate the corresponding interfaces (and resolvers skeletons) for our GraphQL schema but they don't fix the schema <--> models redundancy and developer experience (F2 rename won't work, you have to remember about the codegen watch task in background, etc.), as well as common tasks like validation, authorization, etc.
119+
120+
**TypeGraphQL** comes to address these issues, based on experience from a few years of developing GraphQL APIs in TypeScript. The main idea is to have only one source of truth by defining the schema using classes and some help from decorators. Additional features like dependency injection, validation and auth guards help with common tasks that normally we would have to handle ourselves.
129121

130122
## Documentation
131123

132124
The documentation, installation guide, detailed description of the API and all of its features is [available on the website](https://typegraphql.com/).
133125

134-
## Examples
126+
### Getting started
127+
128+
A full getting started guide with a simple walkthrough (tutorial) can be found at [getting started docs](https://typegraphql.com/docs/getting-started.html).
129+
130+
### Video tutorial
131+
132+
If you prefer video tutorials, you can watch [Ben Awad](https://github.com/benawad)'s [TypeGraphQL video series](https://www.youtube.com/playlist?list=PLN3n1USn4xlma1bBu3Tloe4NyYn9Ko8Gs) on YouTube.
133+
134+
### Examples
135135

136136
You can also check the [examples folder](https://github.com/MichalLytek/type-graphql/tree/master/examples) in this repository for more examples of usage: simple fields resolvers, DI Container support, TypeORM integration, automatic validation, etc.
137137

138138
The [Tests folder](https://github.com/MichalLytek/type-graphql/tree/master/tests) might also give you some tips how to get various things done.
139139

140-
## Towards v1.0
140+
## The future
141141

142-
The currently released version is a MVP (Minimum Viable Product). It is well tested (96% coverage, 8000 lines of test code) and has 95% of the planned features already implemented.
142+
The currently released version is a stable 1.0.0 release. It is well tested (95% coverage, 428 test cases) and has most of the planned features already implemented. Plenty of companies and independent developers are using it in production with success.
143143

144-
However there's still work to be done before the [1.0.0 release](https://github.com/MichalLytek/type-graphql/milestone/3) and it's mostly about documentation (website, api reference and jsdoc) and compatibility with the GraphQL spec and other tools.
144+
However, there are also plans for a lot more features like better TypeORM, Prisma and dataloader integration, custom decorators and metadata annotations support - [the full list of ideas](https://github.com/MichalLytek/type-graphql/issues?q=is%3Aissue+is%3Aopen+label%3A"Enhancement+%3Anew%3A") is available on the GitHub repo. You can also keep track of [development's progress on project board](https://github.com/MichalLytek/type-graphql/projects/1).
145145

146-
There are also plans for more features like better TypeORM, Prisma and dataloader integration, custom decorators and metadata annotations support - [the full list of ideas](https://github.com/MichalLytek/type-graphql/issues?q=is%3Aissue+is%3Aopen+label%3A"Enhancement+%3Anew%3A") is available on the GitHub repo. You can also keep track of [development's progress on project board](https://github.com/MichalLytek/type-graphql/projects/1).
147-
148-
I encourage you to give TypeGraphQL a try and experiment with. If you have any questions, you can [ask on gitter](https://gitter.im/type-graphql/Lobby). If you find a bug, please report it as an issue on GitHub. If you have any interesting feature requests, I would be happy to hear about them.
146+
If you have any interesting feature requests, feel free to open an issue on GitHub so we can discuss that!
149147

150148
## Support
151149

@@ -184,9 +182,12 @@ It doesn't have a large company that sits behind - its ongoing development is po
184182

185183
### Contribution
186184

185+
If you have any questions, you can [ask on gitter](https://gitter.im/type-graphql/Lobby).
186+
If you find a bug, please report it as an issue on GitHub.
187+
188+
If you want to add a new big feature, please create a proposal first, where we can discuss the idea and implementation details. This will prevent wasted time if the PR be rejected.
189+
187190
PRs are welcome, but first check, test and build your code before committing it.
188191

189192
- Use commit rules: For more information checkout this [commit rule guide](https://gist.github.com/stephenparish/9941e89d80e2bc58a153).
190193
- [Allowing changes to a pull request branch created from a fork](https://help.github.com/articles/allowing-changes-to-a-pull-request-branch-created-from-a-fork/)
191-
192-
If you want to add a new big feature, please create a proposal first, where we can discuss the idea and implementation details. This will prevent wasted time if the PR be rejected.

0 commit comments

Comments
 (0)