Skip to content

.load() nullable field returns "Not found" error. #21

@SvenC56

Description

@SvenC56

Hello,

I am trying to query another api from my module which is related by the user module via the email key for each user. Each user can have possibly one api entry belonging to him but it can also be null.

User Module:

user.entity

...
  @Field(() => ApiUser, { nullable: true })
  api?: ApiUser;
...

user.resolver

  @ResolveField(() => ApiUser, { nullable: true })
  async api(
    @Parent() user: User,
    @Loader(ApiUserLoader)
    apiUserLoader: DataLoader<ApiUser["email"], ApiUser>,
  ): Promise<ApiUser> {
    const email = user.email;
    return apiUserLoader.load(email);
  }

API Module:

api-user.loader.ts

  protected getOptions = () => ({
    propertyKey: "email",
    query: async (keys: Array<ApiUser["email"]>) => {
      const users = await this.apiUserService.findByEmails(keys);
      return users;
    },
  });

The API ignores user it does not find. E.g. returns [] for a single entry if it can't find it.

If I query for a user which the external API does not know I get this error by the data loader:

{
  "message": "ApiUser does not exist (example@googlemail.com)",
}

Since the field api in the resolver is nullable I would expect that I get null returned.

Thank you.

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