Describe the bug
When using noNamespace option and typescript-resolvers plugin, gql-gen generates conflicting resolvers if one type Type has a field sampleName, while having a TypeSample type too in the Schema with name property.
To Reproduce
Steps to reproduce the behavior:
Create following schema and run gql-gen
type Task {
id: Int!
stateId: Int!
state: TaskState
}
type TaskState {
id: Int!
}
it creates two resolvers with the same name:
interface TaskResolvers {
stateId: TaskStateIdResolver
}
interface TaskStateResolvers {
id: TaskStateIdResolver
}
Expected behavior
I think there should be a way to put a separator between parent type (namespace) prefix and current field resolver, even something optional just to make it not a breaking change.
Maybe it could be an option in config in order to place a prefix in the resolver name, like here: https://github.com/dotansimha/graphql-code-generator/blob/d5fee64474c9f225e79abbba3d9c4e0328765bfa/packages/plugins/typescript-resolvers/src/helpers.ts#L33
so using something in config like prefixFieldResolverName: Field or just prefixFieldResolverName: "_" we can obtain:
interface TaskResolvers {
stateId: TaskFieldStateIdResolver
// or just
id: Task_StateIdResolver
}
interface TaskStateResolvers {
id: TaskStateFieldIdResolver
// or just
id: TaskState_IdResolver
}
if this sounds good I can work on a PR, let me know if this is already planned or if you would like to implement it in another (maybe better!) way
EDIT: I've proposed fieldResolverNamePrefix implementation in PR #1067
Environment:
@leonardfactory @dotansimha
Maybe we should have a flag to add a suffix that is related to the type of an entity. For example:
type Task {
id: Int!
stateId: Int!
state: TaskState
}
type TaskState {
id: Int!
}
type Task would be interface TaskTypeResolver
Task.stateId would be type TaskStateIdFieldResolver
type TaskState would be interface TaskStateTypeResolver
What do you think? Then we avoid having duplicates.
What do you think? Then we avoid having duplicates.
I think this would change the current behaviour (so all generated types would change, instead this way only Field resolvers would change) – Furthermore I'm not sure about longer resolvers name
Given your example however TaskState.id and Task.stateId would have the same signature (TaskStateIdFieldResolver), unless it's a typo and you mean TaskTypeStateIdResolver (here is Task.stateId) vs TaskStateTypeIdResolver (TaskState.id) – that would make sense.
If I'm correct, are you proposing to add a typeSuffixResolverName instead of a fieldPrefixResolverName option, that would work even with <Type>Resolver (i.e. TaskTypeResolver) other than <Task.field>Resolver (i.e. TaskTypeStateIdResolver)?
I think I'd prefer the former (less characters in the end 😄), but If you think the latter would be better in order to add consistency, It would be perfectly ok: this would resolve my issue as well!
If you want, I can refactor my PR (or open another one) to add this behaviour, if you could suggest me where to change the <Type> name generation. 👍
https://github.com/dotansimha/graphql-code-generator/pull/1067 merged, available in 0.16.0, thanks @leonardfactory !