houdini icon indicating copy to clipboard operation
houdini copied to clipboard

Artifacts type files should get generated with imports for custom data types

Open SeppahBaws opened this issue 2 years ago • 2 comments

Describe the feature

When a query is generated with a field that uses custom data types, the generated MyQuery.d.ts file doesn't contain the import to that type and TypeScript isn't 100% sure on what to do with it, and doesn't provide auto-complete on the type. Additionally, if we have a field e.g. of type Temporal.Instant | null, TypeScript will handle it as any.

Manually placing an import type { Temporal } from "@js-temporal/polyfill"; makes TypeScript happy again.

The config should probably have an additional property on the custom scalar to define an import for said type, so that this is done correctly when the type is generated.

(I think I saw this discussed somewhere before, perhaps on the Discord server, but I can't find it anymore so I'm making this issue to keep track of it 🙂)

Criticality

cool improvement, my projects will benefit from it

SeppahBaws avatar Jul 25 '23 09:07 SeppahBaws

Thanks for opening this! I think where we left off is this:

We could accept and string or an object. treat strings like global types and then make users pass an object that looks like { module: string, type: string } if they want to do something different.

How does that sound to you?

AlecAivazis avatar Jul 25 '23 16:07 AlecAivazis

I think this is a good way to solve it. Might want to hear from some more people on what sort of types they might want to import.

One thing though is e.g. if we have two custom scalars importing two different types from the same package, do we want to do

import type { TypeA } from "@some/package";
import type { TypeB } from "@some/package";

or can we squash them together:

import type { TypeA, TypeB } from "@some/package";

or do we simply not care?

Not entirely sure off the top of my head if typescript will complain about importing from the same package again.

SeppahBaws avatar Jul 25 '23 16:07 SeppahBaws