graphql-code-generator icon indicating copy to clipboard operation
graphql-code-generator copied to clipboard

How to create alias for types?

Open thunderousNinja opened this issue 7 years ago • 2 comments

Describe the bug I am unable to generate aliases for custom types. Here is a snippet from my schema:

type Author {
  id: Id!
  firstName: CustomType!
}

I want CustomType to be an alias of String. I tried adding scalars and primitives mappings in my codegen.yml file for CustomType, but that didn't work. I am still getting an error that says: Unknown type 'CustomType'.

Is it possible to alias standard GQL types? Also, are there any updated docs around the usage of scalars and primitives?

thunderousNinja avatar Feb 07 '19 23:02 thunderousNinja

Hi @thunderousNinja ! It's not possible at the moment, but we are working on refactoring the typescript templates, and that's definitely a use-case we need to consider.

If you wish to override the type because you wish to get a resolvers signature, you can try to use typescript-resolvers plugin, and use generics or specify mappers configuration to override the links between the types.

dotansimha avatar Feb 21 '19 17:02 dotansimha

@thunderousNinja Since 1.0.0, you can provide scalars and it will work :)

dotansimha avatar Mar 19 '19 16:03 dotansimha