FAQ
Design principles
On this page
Gratos keeps the design principles of Grats, which its author set out for it. They are not hard and fast rules, but the principles to consider when making design decisions and tradeoffs. For a concrete description of how Gratos actually works, see How Gratos works.
Integrate into the user's existing code
TypeScript aims to be a type system that models existing JavaScript idioms, rather than asking users to adapt their code style to the type system. Gratos works the same way. Where possible, it lets you build a GraphQL schema by adding docblock tags to your existing code, rather than asking you to adapt your code to an opinionated style.
Progressive disclosure
Gratos has a small, intuitive API. You should feel free to apply docblock tags to your code, confident that Gratos will either do the obvious right thing, or fail with a clear error message that says why what you tried does not work, and what to do instead. So the documentation can stay brief and focused on the happy path, and give guidance about complex cases only as you meet them. In other words, error messages are part of the documentation, disclosed exactly when you need them.
Internal complexity is okay
Gratos is willing to take on internal complexity if that means doing the obviously right thing in more cases. Features that add external complexity or API surface area are avoided where possible.
That said, internal complexity is taken on with caution: a feature or improvement that needs it may wait for an architectural design that keeps the complexity maintainable.
Incremental improvements
There are many kinds of syntax Gratos could learn to parse, and it is not feasible to support all of them at once. Instead, Gratos grows more capable over time, guided by concrete examples of real apps that would benefit. It avoids features that are not immediately useful to real apps.
No new concepts
Gratos avoids introducing new concepts to the GraphQL ecosystem. Docblock tags represent constructs well defined in the GraphQL spec, and should feel familiar to anyone who has used GraphQL in other contexts or languages. Ideally each docblock tag corresponds directly to the GraphQL schema construct it creates.
A few dependencies well leveraged
Gratos has a small number of dependencies, and uses them to their fullest. For example, it uses graphql-js to construct, print and validate GraphQL schemas, rather than its own schema construction and validation. Likewise, it uses TypeScript's own AST parsing, type inference and code printing rather than its own. Gratos adds one dependency to these: Effect, which its CLI is built on, and whose types it reads.
In its public APIs, Gratos exposes the types and concepts of these dependencies, rather than new concepts that would be redundant or confusing.
Where other utilities are needed, Gratos prefers maintaining, forking or vendoring exactly the functionality it needs over depending on a larger library that does more than it needs.
Test-validated behavior
All externally visible behavior is captured by fixture tests, errors included. Every added feature or capability, and every bug fix, comes with a new fixture test that demonstrates the changed behavior.
Fixture tests are narrow: the minimal code needed to demonstrate the behavior tested. It's perfectly fine to have very many of them. For more on how Gratos is tested, see Testing strategy.