Error in the DB's ference, actix-web, sqlx async-graphql

I'm trying to create an api using Actix-web, async-grahpql and sqlx with postgresql

In the QueryRoot of the async-graphql I am trying to capture the reference of the DB and make the query the database with sqlx, but it gives me an error

 let items = Todo::list(&pool).await?;
   |                                ^^^^^ expected struct `sqlx::Pool`, found enum `std::result::Result`

Here I want to capture the reference

use crate::todo::*;
use async_graphql::{Context, FieldResult};
use sqlx::postgres::PgPool;

pub struct QueryRoot;

impl QueryRoot {
    async fn todos(&self, ctx: &Context<'_>) -> FieldResult<Vec<Todo>> {
        let pool =<PgPool>();
        let items = Todo::list(&pool).await?; //<-- This line generates an error

Here I define the references

pub fn run(listener: TcpListener, db_pool: PgPool) -> Result<Server, std::io::Error> {

    let data_db_pool = Data::new(db_pool);

    let schema = Schema::build(QueryRoot, MutationRoot, EmptySubscription)
        .data(data_db_pool.clone()) //<- DB reference

    let server = HttpServer::new(move || {
            .app_data(db_pool.clone()) //<- DB reference
            .route("/graphql", web::post().to(graphql))
            .route("/graphql", web::get().to(graphql_playground))

What am I doing wrong ?

That error means that you forgot to handle an error when you created the pool variable.

I already resolved it

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.