graphql-rust / juniper

GraphQL server library for Rust
Other
5.72k stars 425 forks source link

the graphql macro is being ignored #1140

Closed PumpedSardines closed 1 year ago

PumpedSardines commented 1 year ago

Describe the bug the graphql macro is being ignored when used for parameters.

To Reproduce Heres a snippet of my code. When entering the playground the parameter for user will be userId not id.

use super::{resolvers, GraphQLContext};
use diesel::prelude::*;
use juniper::graphql_object;

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

    pub fn user(
        context: &GraphQLContext,
        #[graphql(name = "id")] user_id: i32,
    ) -> Option<resolvers::user::User> {
        let pool = &context.pool;
        let conn = &mut pool.get().unwrap();

        use database::schema::users;

        let user = users::table
            .filter(users::id.eq(user_id))
            .first::<database::models::User>(conn)
            .optional()
            .expect("Error loading users");

        if user.is_none() {
            return None;
        }

        let user = user.unwrap();

        Some(resolvers::user::User {
            id: user_id,
            username: user.username,
        })
    }
}

Expected behavior The parameter name should be id not userId

Additional context When running the juniper_actix example this does not happen.

Here's my Config.toml:

[package]
name = "graphql"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
database = { path = "../database" }
r2d2 = "0.8.9"
juniper = { version = "0.15.10", features = ["expose-test-schema"] }
diesel = { version = "2.0.0", features = ["postgres", "r2d2"] }
tyranron commented 1 year ago

@PumpedSardines this syntax is available on latest master only. For juniper 0.15 you should use:

    #[graphql(arguments(user_id(name = "id")))]
    pub fn user(
        context: &GraphQLContext,
        user_id: i32,
    ) -> Option<resolvers::user::User> {

See details in Book for that version: https://github.com/graphql-rust/juniper/blob/juniper-v0.15.10/docs/book/content/types/objects/complex_fields.md#customizing-arguments

PumpedSardines commented 1 year ago

Thanks