Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/captbaritone/grats

Implementation-First GraphQL for TypeScript
https://github.com/captbaritone/grats

code-first graphql graphql-server typescript

Last synced: 20 days ago
JSON representation

Implementation-First GraphQL for TypeScript

Awesome Lists containing this project

README

        

# Grats: Implementation-First GraphQL for TypeScript

[![Join our Discord!](https://img.shields.io/discord/1089650710796320868?logo=discord)](https://capt.dev/grats-chat)

_Beta Software: Grats is largely stable and being used in production in multiple places. If you encounter any issues, don't hesitate to let us know._

**The simplest way to build a GraphQL server in TypeScript**

When you write your GraphQL server in TypeScript, your fields and resolvers
are _already_ annotated with type information. _Grats leverages your existing
type annotations to automatically extract an executable GraphQL schema from your
generic TypeScript resolver code._

By making your TypeScript implementation the source of truth, you never have to
worry about validating that your implementation matches your schema. Your
implementation _is_ your schema!

Read the [blog post](https://jordaneldredge.com/blog/grats).

## Example

Here's what it looks like to define a User type with a greeting field using Grats:

```ts
/** @gqlType */
class User {
/** @gqlField */
name: string;

/** @gqlField */
greet(args: { greeting: string }): string {
return `${args.greeting}, ${this.name}`;
}
}
```

After running `npx grats`, you'll find a `schema.ts` module that exports an executable schema, and a `schema.graphql` file contains your GraphQL schema definition:

```graphql
type User {
name: String
greet(greeting: String!): String
}
```

That's just the beginning! To learn more, **Read the docs: https://grats.capt.dev/**

## Contributing

See [`CONTRIBUTING.md`](./CONTRIBUTING.md) in the repo root for details on how to make changes to this project.

# Acknowledgements

- [@mofeiZ](https://github.com/mofeiZ) and [@alunyov](https://github/alunyov) for their Relay hack-week project exploring a similar idea.
- [@josephsavona](https://github.com/josephsavona) for input on the design of [Relay Resolvers](https://relay.dev/docs/guides/relay-resolvers/) which inspired this project.
- [@bradzacher](https://github.com/bradzacher) for tips on how to handle TypeScript ASTs.
- Everyone who worked on Meta's Hack GraphQL server, the developer experience of which inspired this project.
- A number of other projects which seem to have explored similar ideas in the past:
- [ts2gql](https://github.com/convoyinc/ts2gql)
- [ts2graphql](https://github.com/cevek/ts2graphql)
- [typegraphql-reflection-poc](https://github.com/MichalLytek/typegraphql-reflection-poc)

## License

Grats is [MIT licensed](./LICENSE).