Introduction

Introduction

Public Type-Safe Query is a powerful library designed for building type-safe APIs with full-stack TypeScript environment. With PTSQ, you gain access to advanced features like introspection of your API schema, making it effortless to create type-safe queries, mutations, middlewares, and more. This ensures that your API interactions are robust, predictable, and maintainable, regardless of the programming language used on the client side. Whether you're working with complex data structures or integrating multiple services, PTSQ streamlines the development process, empowering you to build scalable and reliable APIs with ease.

Motivation

Both tRPC (opens in a new tab) and GraphQL (opens in a new tab) offer compelling features for building type-safe backends, but each has its limitations. While tRPC provides type safety, it lacks schema introspection, making it unsuitable for creating type-safe open APIs. Conversely, GraphQL offers schema introspection, enabling type-safe open APIs, but setting up projects and writing resolvers can be complex.

This library, however, bridges the gap between these two worlds by combining the best features of both approaches. It provides the type safety of tRPC while also offering schema introspection capabilities akin to GraphQL. With this library, developers can enjoy the ease of use and simplicity of tRPC while benefiting from the flexibility and openness of GraphQL's schema introspection, resulting in a powerful and versatile solution for building type-safe APIs.

Requirements

You have to enable strictNullChecks or use strict mode which includes strictNullChecks. Otherwise Typebox cannot correctly infer the types of your schemas.

tsconfig.json
{
  "$schema": "https://json.schemastore.org/tsconfig",
  //...
  "compilerOptions": {
    "strictNullChecks": true // <- must be true
    //...
  }
  //...
}