apollographql / apollographql/apollo-tooling
Feature Request: Generate an `index.ts` file in codegen for typescript
- Dominant language
- TypeScript
- Stars
- 3k
- Forks
- 460
- PR merge metrics
- No merged PRs in 30d
Description
I'd like to make it easier to import many codegen'd query type definitions at one time.
### Problem Statement
Currently the typescript generator will generate a different file for each query.
Currently if a single file component uses multiple queries, it might import the queries like so:
```ts
import { GetUser } from "myqueries/GetUser";
import { GetFoo } from "myqueries/GetFoo";
import { GetBar } from "myqueries/GetBar";
```
### Ideal Solution
Typescript codegen could also generate an `index.ts` file in the subdirectory that re-exports all of the queries.
It would be convenient to instead be able to do either:
```ts
// Import queries as namespace
import queries from "myqueries";
let something: queries.GetFoo = ...;
// Import specific queries in single import statement
import { GetUser, GetFoo } from "myqueries";
```
The generated `index.ts` file could look like:
```ts
export * from "./GetBar";
export * from "./GetFoo";
export * from "./GetUser";
```
or more conservatively
```ts
export { GetBar } from "./GetBar";
export { GetFoo } from "./GetFoo";
export { GetUser } from "./GetUser";
```
### Affected Projects
As far as I know, only `apollo-codegen-typescript` would be affected.
Contributor guide
Research direction
Start at the apollo-codegen-typescript generator and trace how it writes one file per query. Add the generated index.ts alongside those query files, re-exporting the generated definitions so grouped imports work, and verify that the output matches the requested examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100