Gratos has some known limitations. Some are innate, and some could be lifted with effort. In the interest of transparency, they are documented here. The method wrapper and the inferred type below are real files that gratos rejects, and a test checks that it still does. The union enum compiles, and its schema shows what Gratos leaves out.

Method wrappers

Sometimes it is useful to wrap a method in a function, which can emulate a decorator. For example:

method-wrapper.ts
import type { ID } from "gratos";

/** @gqlType */
class User {
  /** @gqlField */
  approve_post = requireAuthed(({ id }: { id: ID }) => {
    Post.approve(id);
    return true;
  });
}

Gratos cannot handle this, because it cannot "see" what type the wrapper function returns, or what arguments the returned function accepts. It reports that the field needs an explicitly defined type annotation.

Inferred types

In theory, Gratos could ask TypeScript which type it infers in a given position. For example, TypeScript infers that this function returns string, so we shouldn't need to annotate its return type:

inferred-type.ts
/** @gqlType */
type User = {
  /** @gqlField */
  name: string;
};

/** @gqlField */
export function name(_: User) {
  return "John";
}

But this is not a good fit for GraphQL's type system, which is "nominal", whereas TypeScript's is "structural". See Structural vs nominal typing for more details. Gratos reports that the field needs an explicit return type.

Descriptions and @deprecated on TypeScript union @gqlEnums

Gratos does not support descriptions or @deprecated on the values of a GraphQL enum defined as a TypeScript union. The schema has neither:

MyEnum.ts
/** @gqlEnum */
type MyEnum =
  /** This gets ignored */
  | "A"
  /** So does this */
  | "B";

This is because we rely on the TypeScript compiler to tell us which docblocks are "attached" to a given AST node, and TypeScript doesn't see those comments as attached to anything. We could explore implementing our own comment attachment in the future, but it is a difficult problem.

Alternate comment types

It would be nice if Gratos supported other kinds of comments, such as regular block comments (with one *) or line comments (starting with two slashes). But it can't.

The reason is the same: we rely on the TypeScript compiler to tell us which docblocks are "attached" to a given AST node, and TypeScript attaches only JSDoc comments.