Is there any reason why we use export type instead of export interface?
Also, it is kinda confusing that some types / interfaces are prefixed with I while others are not. In my opinion, nothing should be prefixed by default and the prefix should only be added depending on the typesPrefix option.
Right now when doing typesPrefix: I, some types have 2 I prefixed.
@P4sca1 which version do you use? I assume it's typesPrefix because it's there from v1.0.0.
Can you provide an example for types that are being prefixed by default? I think we only have it in IResolvers
Also, we chose to use type because it's easier to use it to create type aliases, and most of the types are not intended to be inherited because they reflect the schema, and interface has a connotation of something you should inherit/implement.
Also, TypeScript interfaces can be declared multiple times in the same scope, making it harder for us to test if there are duplicated types generated.
interface A {
a1: string;
}
interface A { // No error, and "A" will have both fields
a2: string;
}
While types can be declared only once:
typescript
type A = {
a1: string;
}
type A = { // Error
a2: string;
}
Okay that makes sense now.
For the prefix, it was only for some interfaces, maybe only IResolvers (I don鈥檛 remember atm, need to check).
Maybe we should change typesPrefix to only prefix types not interfaces then (because they are prefixed by default)?
@P4sca1 I think it's only IResolvers, @ardatan maybe we should remove it? I think you added it.
@P4sca1 I fixed it here:
https://github.com/dotansimha/graphql-code-generator/pull/1534
I'm generating Resolvers as the root, and IResolvers pointing to Resolvers with @deprecated comment (for backward compatibility), and if you'll provide typesPrefix, it will override it.
(Also, did the same of IDirectiveResolvers)
LGTM!
Most helpful comment
@P4sca1 I fixed it here:
https://github.com/dotansimha/graphql-code-generator/pull/1534
I'm generating
Resolversas the root, andIResolverspointing toResolverswith@deprecatedcomment (for backward compatibility), and if you'll providetypesPrefix, it will override it.(Also, did the same of
IDirectiveResolvers)