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

Avoid to return null entities in lists #3643

Open
alessandrolulli opened this issue Sep 23, 2024 · 0 comments
Open

Avoid to return null entities in lists #3643

alessandrolulli opened this issue Sep 23, 2024 · 0 comments

Comments

@alessandrolulli
Copy link

alessandrolulli commented Sep 23, 2024

Dear,

we are finding ourselves to understand how it is possible to remove null data in list in the result.

For instance, given the schema of a user, where the user is inside a list of users.data

@strawberry.type
class User:
    id: int
    name: str

We are searching the user in the subfields exploiting the dataloaders and not resolving the entire users in the user resolver.

def resolve_user(info: strawberry.Info, filters) -> str: <-- this is just propagating the ids to the sub type
    return filters.ids <-- [1,2,3,9999]

def resolve_name(root: "User", info: strawberry.Info) -> str:
    return dataloader.load(root.id).name

I want the users [1,2,3,9999].
What happen is while resolving the name of user 9999 the user is not found and we have nothing to assign to the relative name throwing an error because name can not be null. The error is propagated upper and we nullify the entire user.

Our result is [user 1, user 2, user 3, null].
Is there a way in strawberry to remove the null in the returned list? How is it possible to act in a post process like that?

Thanks

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant