Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Resolver Called via Field Resolver #712

Closed
mikewzorek opened this issue Oct 1, 2020 · 2 comments
Closed

Nested Resolver Called via Field Resolver #712

mikewzorek opened this issue Oct 1, 2020 · 2 comments
Labels
Question ❔ Not future request, proposal or bug issue Solved ✔️ The issue has been solved

Comments

@mikewzorek
Copy link

mikewzorek commented Oct 1, 2020

Hello,

I have an implementation based on #312 (comment) that was working in 0.17.6 however the "nested" resolver is no longer being called after upgrading to 1.0.0 and graphql to 15.3.0. Here's my implementation:

@ObjectType()
@InputType('SurveyResultInput')
export class SurveyResult {
  @Field()
  programId!: string;

  @Field()
  numberOfVotes!: number;
}

@Resolver(() => Survey)
export class SurveyResolver {
  @Query(() => Survey)
  async getCompletedSurvey(
    @Arg('propertyId', { nullable: false }) propertyId: string,
    @Arg('tenantBrandId', { nullable: false }) brandId: string,
    @Ctx() ctx: Context
  ) {
    try {
      const survey = await ctx.dataSources.surveyService.getSurveyResultsByPropertyAndTenant(
        propertyId,
        brandId
      );
      return survey;
    } catch (error) {
      throw new ApolloError(error);
    }
  }

  @FieldResolver(() => [SurveyResult])
  async results(@Root() survey: Survey, @Ctx() ctx: Context) {
    const resp = await ctx.dataSources.surveyService.getSurveyResultsByPropertyAndTenant(
      survey.propertyId,
      survey.brandId
    );
    return resp.results;
  }
}

@Resolver(() => SurveyResult)
export class SurveyResultResolver {
  @FieldResolver(() => Program)
  async program(@Root() result: SurveyResult, @Ctx() ctx: Context) {
    const program = await ctx.dataSources.matchmakingService.getProgramDetails(result.programId);
    return program;
  }
}

The program field resolver is no longer getting called despite the same graphql query.

  query getCompletedSurvey($propertyId: String!, $tenantBrandId: String!) {
    getCompletedSurvey(propertyId: $propertyId, tenantBrandId: $tenantBrandId) {
      results {
        programId
        numberOfVotes
        program {
          name
          nonprofit {
            name
          }
        }
      }
    }
  }

Thanks for the wonderful library and any help!

@MichalLytek
Copy link
Owner

Are both SurveyResolver and SurveyResultResolver resolvers imported and used in resolvers array of buildSchema?

@MichalLytek MichalLytek added Need More Info 🤷‍♂️ Further information is requested Question ❔ Not future request, proposal or bug issue labels Oct 1, 2020
@mikewzorek
Copy link
Author

SurveyResultResolver was not. I added that and fixed it. Thanks for the help and quick reply!

@MichalLytek MichalLytek added Solved ✔️ The issue has been solved and removed Need More Info 🤷‍♂️ Further information is requested labels Oct 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question ❔ Not future request, proposal or bug issue Solved ✔️ The issue has been solved
Projects
None yet
Development

No branches or pull requests

2 participants