Skip to content

Add grouped object exports for query functions and query hooks in generated -components file #307

@yekver

Description

@yekver

Right now , the generated -components file exports a flat list of types, query functions, and query hooks.
While this is simple and works fine for small schemas, it becomes difficult to work with when:

  • The schema is large and includes many endpoints
  • Multiple schemas are used across the project

In these cases, it’s hard to discover or autocomplete the correct function or hook by name.

Proposal

In addition to the current flat exports, introduce grouped object exports:

  1. Fetches – an object that groups all fetch functions
  2. Queries – an object that groups all query/mutation hooks
  3. QueryOptions - an object that groups all queryOptions objects used by query hooks

Example:

export const getPets = ...
export const useGetPets = ...
export const getPetsQueryOptions = ...

export const createPet = ...
export const useCreatePet = ...
export const createPetMutationOptions = ...

// Grouped exports

export const Fetches = { getPets, createPet };
export const Queries = { useGetPets, useCreatePet };
export const QueryOptions = {
  getPets: getPetsQueryOptions,
  createPet: createPetMutationOptions,
};

Usage

With the proposed grouped exports, it’s easy to build a single client entry point that aggregates all schemas:

// apiClient.ts
import * as Petstore from './api/petstoreComponents';
import * as Payments from '.api/paymentsComponents';
import * as Admin from './api/adminComponents';

export const API = { Petstore, Payments, Admin };

Then throughout your application, you can access everything in a clear and organized way:

API.Petstore.Queries.useGetPets();
API.Payments.Fetches.getPaymentDetails();
API.Admin.QueryOptions.getAdminUsers();

I believe this makes working with large or multi-schema APIs intuitive and reduces the cognitive load of searching for auto-generated names or digging through individual files.

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