Say I have the following schema:
type CodeName {
code: Int!
name: String!
}
type Person {
id: Int!
weapon: Weapon
hat: Hat
codeName: CodeName!
}
type Weapon {
id: Int!
type: String!
codeName: CodeName!
}
type Hat {
id: Int!
size: Int!
codeName: CodeName!
}
type Query {
Person(id: Int!): Person!
Weapon(id: Int!): Weapon!
Hat(id: Int!): Hat!
}
then, I would define my resolvers like so:
const resolvers = {
Weapon: {
codeName: CodeNameResolver,
},
Hat: {
codeName: CodeNameResolver,
},
Person: {
codeName: CodeNameResolver,
weapon: WeaponResolver,
hat: HatResolver
},
Query: {
Person: PersonResolver,
Weapon: WeaponResolver,
Hat: HatResolver,
}
}
However, I have to repeat codeName: CodeNameResolver multiple times in the code, every time I have a field whose type is CodeName.
Is there a way to use a global field resolver, or type resolver, so that I don't have to do that?