and then, in each query of each modules I wanted to do this:
\nExample: [users/query.rs]
\nuse juniper::{graphql_object, FieldError, FieldResult};\n\nuse crate::graphql::schema::Context;\nuse crate::graphql::query::QueryRoot;\nuse crate::graphql::users::schema::User;\n\n\n#[graphql_object(context = Context)]\nimpl QueryRoot {\n pub async fn get_user_by_id(context: &Context, id: i32) -> FieldResult<User> {\n let sql = r#\"\n select\n id::int4,\n email,\n documento\n from\n auth_users\n where\n id = $1\n \"#;\n let data = sqlx::query_as::<_, User>(sql)\n .bind(id)\n .fetch_one(&context.pool)\n .await;\n\n match data {\n Ok(user) => Ok(user),\n _ => Err(FieldError::from(\"no se encontró el usuario\")),\n }\n }\n\n pub async fn get_all_user(context: &Context, page: i32, page_size: i32) -> FieldResult<Vec<User>> {\n let sql = r#\"\n select\n id::int4,\n email,\n documento\n from\n auth_users\n order by\n id\n OFFSET $1*$2 LIMIT $2;\n \"#;\n let data = sqlx::query_as::<_, User>(sql)\n .bind(page)\n .bind(page_size)\n .fetch_all(&context.pool)\n .await.unwrap();\n\n Ok(data)\n }\n}\nI get this error:
\n\n\nsrc/graphql2/users/query.rs:8:1
\n
\n|
\n8 | #[graphql_object(context = Context)]
\n| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation forgraphql::query::QueryRoot
\n|
\n::: src/graphql/query.rs:14:1
\n|
\n14 | #[graphql_object(context = Context)]
\n| ------------------------------------ first implementation here
\n|
\n= note: this error originates in the attribute macrographql_object(in Nightly builds, run with -Z macro-backtrace for more info)
If I do not use #[graphql_object(context = Context)] in users/query.rs the functions are not available
\nI also tried to use the functions of users/query.rs a root query.rs and use them in the impl of QueryRoot
\npub struct QueryRoot;\n\n\n#[graphql_object(context = Context)]\nimpl QueryRoot {\n async fn api_version() -> &str {\n \"0.1\"\n }\n async fn get_user_by_id(context: &Context, id: i32) -> FieldResult<User> {\n get_user_by_id(context, id).await\n }\n\n async fn get_all_user(context: &Context, page: i32, page_size: i32) -> FieldResult<Vec<User>> {\n get_all_user(context, page, page_size).await\n }\n}\n\nThe above works fine, but I don't like to have to redefine each of the functions
","upvoteCount":1,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"This #646 (comment) works for me
","upvoteCount":1,"url":"https://github.com/graphql-rust/juniper/discussions/1141#discussioncomment-4720082"}}}-
|
Hi What is the best way to modularize an API? I tried the following: ├── main.rs In root query.rs I have: and then, in each query of each modules I wanted to do this: Example: [users/query.rs] I get this error:
If I do not use #[graphql_object(context = Context)] in users/query.rs the functions are not available I also tried to use the functions of users/query.rs a root query.rs and use them in the impl of QueryRoot The above works fine, but I don't like to have to redefine each of the functions |
Beta Was this translation helpful? Give feedback.
-
|
This #646 (comment) works for me |
Beta Was this translation helpful? Give feedback.
This #646 (comment) works for me