#Embedded graphql resolvers (i.e. resolving second level fields)

4 messages · Page 1 of 1 (latest)

floral halo
#

I have a graphql schema similar to this:

{
  type PersonProfile {
    name: String!
    address: String
    isValidated: Boolean
  }

  profile: PersonProfile
}

This is a contrived example, but I don't want the resolver to be on the PersonProfile in this example... I want three separate resolvers on name, address, isValidated. How do I do this?

I've tried a few ways, but they never fire.

@ResolveField('name')
public async name() {
  return "shawn"
}
@Resolver('profile')
@ResolveField('name')
....

and

@ResolveField('profile.name')
...
slow kelp
#

Is this schema-first?

floral halo
#

@slow kelp Yes it is.

slow kelp
#

I think you need @Resolver('PersonProfile') on top of export class PersonProfileResolver, and within the class

@ResolveField('name')
public async name() {
  return "shawn"
}

@Query('profile')
public async getProfile() { return something; }