Skip to content

TResult type idea #8

Description

@jardakotesovec

Hi,
I am trying out the push the types in resolvers to the limit with new options :-).

In my use case TParent is usually needed to retype to the model types (as often some additional fields that are not exposed via graphql are being used), but that still looks very good as it can be nicely defined per graphql type, like this :

  type Study {
    _id: ObjectId!
    ready: Bool!
    studyDescription: StudyDescription!
    referringPhysicians: [ReferringPhysician]! 
  }


const studyResolvers: GQLStudyTypeResolver<MStudy> = {
  referringPhysicians(study, {}, ctx) {
    return loadReferringPhysicianByIds(ctx, study.referringPhysicianIds);
  },
  studyDescription(study, {}, ctx) {
    if (!study.studyDescriptionId) {
      return null;
    }
    return loadStudyDescriptionById(ctx, study.studyDescriptionId);
  },
};

But thinking about following improvement that I believe could make the result type significantly more useful, don't know how difficult be to add that in.

In this example smartTResult type requires that resolver which is returning GQLStudy would have return all fields (_id, read, studyDescription and referringPhysicians), but in fact since Study type has own resolvers for referringPhysicians and studyDescription ideally it should not require these fields (make them optional) when resolving Study type and require only _id and ready.

That would require to not just look at what type is being returned, but also look into the resolvers if there are some field resolvers.

What do you think, does it make sense?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions