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

Issue with nullable reference when using federation #1051

Closed
mwoelk opened this issue Apr 8, 2021 · 0 comments · Fixed by #1055
Closed

Issue with nullable reference when using federation #1051

mwoelk opened this issue Apr 8, 2021 · 0 comments · Fixed by #1055
Labels
bug Something isn't working

Comments

@mwoelk
Copy link
Contributor

mwoelk commented Apr 8, 2021

Describe the bug
When using a nullable @Reference, there are two small issues.

  • The 4th argument of the @Reference decorator is used to set the relation to nullable. But only passing {nullable: true} leads to a type error because it also expects a key property which should have also been omitted here:
    export type ReferenceDecoratorOpts<DTO, Relation> = Omit<ResolverRelationReference<DTO, Relation>, 'DTO'>;
  • Even if the referencedId is null, an object is returned with a typename and a null reference.
    [`${baseNameLower}Reference`](@Parent() dto: DTO): RepresentationType {
    // eslint-disable-next-line @typescript-eslint/naming-convention
    return { __typename: baseName, ...pluckFields<DTO, Relation>(dto, reference.keys) };
    }

    It should return null otherwise we get the error that the id field on the referenced type is not nullable!

Have you read the Contributing Guidelines?

yes

To Reproduce
Steps to reproduce the behavior:

  1. Use federation
  2. Have one DTO define a reference of another external DTO that can be nullable

Expected behavior
In case of a nullable reference, the resolver should return null instead of a typename with an id of null.

Desktop (please complete the following information):

  • Node Verson [14.13.1]
  • Nestjs-query Version [v0.25.1]
@mwoelk mwoelk added the bug Something isn't working label Apr 8, 2021
mwoelk added a commit to mwoelk/nestjs-query that referenced this issue Apr 8, 2021
mwoelk added a commit to mwoelk/nestjs-query that referenced this issue Apr 8, 2021
mwoelk added a commit to mwoelk/nestjs-query that referenced this issue Apr 9, 2021
mwoelk added a commit to mwoelk/nestjs-query that referenced this issue Apr 9, 2021
@doug-martin doug-martin linked a pull request Apr 12, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant