Skip to content

tRPC: detect imported procedures and treat as first-class concept #26

@glorat

Description

@glorat

Problem

tRPC routers that import procedures from separate files are not detected. This pattern is common in larger tRPC codebases, where each procedure lives in its own file.

// src/router.ts
import { router } from "./trpc";
import { getUsers } from "./procedures/getUsers";
import { createUser } from "./procedures/createUser";

export const appRouter = router({
  getUsers,       // ShorthandPropertyAssignment — not detected
  createUser,     // ShorthandPropertyAssignment — not detected
  inline: publicProcedure.query(async () => "ok"),  // detected ✓
});

Issues

  • Only inline procedure chains (.query(), .mutation()) are detected.
  • Imported procedures using shorthand syntax produce zero routes.
  • Most real-world tRPC projects end up with incomplete route coverage.
  • Detected tRPC procedures are incorrectly grouped under "GraphQL" due to shared method names (QUERY, MUTATION, SUBSCRIPTION), which is misleading.

Proposed Changes

1. AST Enhancements: Support Missing tRPC Patterns

Add handling for the following patterns:

  • Shorthand Property Assignment

    router({ getUsers })
  • Identifier Initializer

    router({ getUsers: getUsersProcedure })
  • Nested Namespace Objects

    router({ admin: { users: usersRouter } })

2. Treat tRPC as a First-Class Concept

  • Filter routes using:

    framework === "trpc"

    instead of relying on method names.

  • Render a dedicated section:

    ## tRPC Procedures
    
  • Standardize all detected procedures to:

    method: PROCEDURE
    
  • Do not attempt to resolve query vs mutation:

    • Requires fragile import resolution
    • Provides minimal value in this context
    • The distinction can be determined when inspecting the source file

3. Deduplicate tRPC Routes

  • When both AST and regex fallback detect the same procedure:

    • Prefer the AST result

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions