prisma-labs / graphqlgen

⚙️ Generate type-safe resolvers based upon your GraphQL Schema
MIT License
818 stars 54 forks source link

Allow using `import` in model files #473

Open Yuyz0112 opened 5 years ago

Yuyz0112 commented 5 years ago

Description

Currently, I found we could not use types imported from other files in the model file. For example, if I have two typescript files like this:

// types.ts
export type A = 'A' | 'a'
// models.ts
import { A } from './types.ts'

export interface Entity {
  a: A
}

If trying to generate this model file, graphqlgen will throw an error about TypeError: Cannot read property 'kind' of undefined. After some debugging, I found this is because of graphqlgen cannot build type getter for the imported type A.

I have seen something like filesToTypesMap and addFileToTypesMap are related to this, but looks like they are used for testing. So is it possible to have this kind of import working?

Additional context

I think this is useful when using graphqlgen with Prisma because Prisma will generate types according to the enums in the datamodel. And custom models may use this enum which needs to import types from the generated Prisma client types.