-
| Here's my query: And the response: Since not all users are on a team I would expect to get all users back and just have the team section be null. Here's the code:  | 
Beta Was this translation helpful? Give feedback.
      
      
          Answered by
          
            tyranron
          
      
      
        Sep 29, 2022 
      
    
    Replies: 1 comment 2 replies
-
| @twiclo your  To make it  #[graphql_object(context = Context)]
impl User {
  async fn team(&self, ctx: &Context) -> FieldResult<Option<Team>> {
    // and return `Ok(None)` whenever you want to return `null`
  }
}Or if you want to turn any error into  #[graphql_object(context = Context)]
impl User {
  async fn team(&self, ctx: &Context) -> Option<Team> {
    Ok(Team::get_users_team(validate_perm(&ctx.user.perms).ok()?, ctx, self.user_id).await.ok()?)
  }
} | 
Beta Was this translation helpful? Give feedback.
                  
                    2 replies
                  
                
            
      Answer selected by
        twiclo
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
@twiclo your
User.teamfield cannot benull, because you've declared it as non-nullable type in the schema.To make it
nullable, you should declare the computable field to return thenullable type:Or if you want to turn any error into
null(which I don't recommend), just don't use theResult, onlyOption: