apollo-tooling
apollo-tooling copied to clipboard
Feature Request: Generate an `index.ts` file in codegen for typescript
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:
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:
// 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:
export * from "./GetBar";
export * from "./GetFoo";
export * from "./GetUser";
or more conservatively
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.
Could there be any possible name conflicts?
This would be super usefull in my case.
Context: I'm using the generated types as a seperate package in a monorepo. I wish i could set up an index.ts with all the generated types as the main
file in package.json
.
Does anyone have an idea on how to do this until it's implemented?
@cglacet I used graphql-code-generator which allows you easily do this, they use apollo-tooling under the hood.
@antoniojps Could you point me on how to create an index.ts
file that exports *
in all the *.ts
in the same directory with graphql-code-generator?