Skip to content

Generate API operation mappings for frontend apiOptions inference #131202

Open

Description

@betegon

Part of v1.0.0 getsentry/sentry-api-schema#93. This is the first frontend adoption slice: use generated API contracts inside the existing apiOptions abstraction while retaining the frontend's current request execution.

Outcome

A schema-covered query should infer its inputs and response without repeating an SDK operation, writing a manual queryFn, or adapting errors in each component. Existing apiOptions.as<T>() calls remain supported.

Illustrative target API; this inferred signature does not exist today:

const query = useQuery(
  apiOptions('/organizations/$organizationIdOrSlug/projects/', {
    path: {organizationIdOrSlug: organization.slug},
    staleTime: 30_000,
  })
);

The frontend already has a TODO to infer responses from an ApiMapping. Build on that seam rather than introducing a competing query API.

SDK-owned work

  • Generate and export an aggregate operation map keyed by canonical endpoint and HTTP method, reusing generated input, success-response, and error types.
  • Describe path/query/body inputs and preserve optionality, supported methods, and response unions. Avoid manual per-endpoint registration and casts.
  • Keep contract consumption type-only where possible; importing the map must not pull in the runtime client, React, TanStack, or validators.
  • Verify regeneration and type inference against representative read, mutation, and paginated operations, including a type-only import from the packed package.

Shared frontend integration

  • Connect the map to apiOptions / infinite options once. Resolve the mapping from canonical OpenAPI routes and parameters to frontend $parameter routes during generation or shared integration, never in each query. Verify aliases and ambiguous/missing matches.
  • Preserve existing call sites, query keys, invalidation, skipToken, staleTime, selectors, and cache shape {json, headers, status?}.
  • Keep apiFetch → Client as the runtime path for this phase. It continues producing the actual RequestError and applying existing auth, sudo, routing, credentials, CSRF, and retry policies. No error conversion, WeakMap, constructor injection, or per-query adapter is needed for this phase.
  • Keep TanStack error typing honest: the map describes API response contracts, not an exhaustive checked exception channel. Do not globally declare that every query error is SentryApiError or RequestError.
  • Retain .as<T>() for internal/getsentry endpoints absent from the public schema and for deliberate compatibility cases. Do not silently replace richer frontend types with incomplete public responses or publish private endpoints to eliminate the fallback.
  • Compile representative existing and inferred call sites, including unknown/private-route fallback; verify existing cache keys and selectors remain compatible.

Scope and sequencing

This can proceed alongside the transport foundation in getsentry/sentry-api-schema#94, getsentry/sentry-api-schema#95, getsentry/sentry-api-schema#92, and the auth/routing work. It does not require a generic TanStack plugin.

This is adoption of the SDK's schema/type contracts, not adoption of its runtime requests, retries, or pagination. It must not be used to mark the frontend runtime release gate complete. The subsequent runtime integration is tracked separately in #103.

The SDK team owns the generated contract and reusable integration support. A focused frontend PR connects the existing abstraction; feature teams should not write adapter code in their components.

Relationship to routing metadata

#81's backend routing-metadata work does not make this type-only phase depend on an SDK router. Keep canonical method/route identities compatible with that metadata, but retain apiFetch → Client and current frontend routing. Generated type inference must not silently select hosts, perform discovery or introduce a cache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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