Skip to content

I'm having issues with App Data configuration #1171

Closed
@seun-ja

Description

@seun-ja

Discussed in #1170

Originally posted by seun-ja June 21, 2023
I'm currently working on a web app project. It's built using Actix and for the database, Postgres. I'm currently trying to implement Graphql, read the documentation even followed an example using Actix in the repo yet I get this response

Requested application data is not configured correctly. View/enable debug logs for more details.

let graphql_schema = Data::new(schema());

HttpServer::new(move || {
        App::new()
            .wrap(TracingLogger::default())
            .wrap(
                Cors::default()
                    .allow_any_origin()
                    .allowed_methods(vec!["POST", "GET", "PUT", "DELETE"])
                    .allowed_headers(vec![
                        header::AUTHORIZATION, 
                        header::ACCEPT, 
                        header::DATE, 
                        header::CONTENT_LENGTH,
                        ])
                    .allowed_header(header::CONTENT_TYPE)
                    .supports_credentials()
                    .max_age(3600),
            )
            .route("/", web::get().to(home))
            .route("/health_check", web::get().to(health_check))
            .route("/graphql", web::post().to(graphql))
            .route("/graphiql", web::get().to(graphiql)),
            )
            .app_data(db_pool.clone())
            .app_data(graphql_schema.clone())
            .app_data(schema_context.clone())
            
    })
    .listen(listener)?
    .run()
pub async fn graphql(
    st: web::Data<Schema>, 
    data: web::Json<GraphQLRequest>,
    ctx: web::Data<Context>,
) -> Result<HttpResponse, actix_web::Error> {
    let res = data.execute(&st, &ctx).await;

    let res_data = serde_json::to_string(&res).unwrap();

    Ok(HttpResponse::Ok()
        .content_type("application/json")
        .body(res_data))
}
#[derive(Clone, Debug)]
pub struct Query;

#[graphql_object(context = Context)]
impl Query {
    fn api_version() -> &'static str {
        "1.0"
    }

    fn streamlink(
        &self,
        ctx: &Context,
        id: String,
    ) -> FieldResult<Stream> {
        let link = get_stream_link(id, &ctx.pool)
            .map_err(|_e| {
                return FieldError::<DefaultScalarValue>::new(
                    "Product Not Found",
                    graphql_value!({ "not_found": "product not found" }),
                );
            })
            .unwrap();

        Ok(Stream {
            link
        })
    }
}

pub type Schema = RootNode<'static, Query, EmptyMutation<Context>, EmptySubscription<Context>>;

pub fn schema() -> Schema {
    Schema::new(Query, EmptyMutation::<Context>::new(), EmptySubscription::<Context>::new())
}

what could I be missing :(

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already existslib::actixRelated to `actix` crate integrationsupport

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions