Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does async-graphql validate responses? #1507

Open
RaphaelDarley opened this issue Apr 1, 2024 · 0 comments
Open

Does async-graphql validate responses? #1507

RaphaelDarley opened this issue Apr 1, 2024 · 0 comments
Labels
question Further information is requested

Comments

@RaphaelDarley
Copy link

RaphaelDarley commented Apr 1, 2024

I was under the impression that async-graphql checked if the response conformed to the schema, and remember seeing errors for it, but now it seems not too.

nb: I've tried switching to version 7, but this doesn't seem to make any difference

[dependencies]
async-graphql = { version = "6", features = ["dynamic-schema"] }
async-graphql-axum = "6"
axum = "0.6"
tokio = { version = "1.36.0", features = ["full"] }
use async_graphql::http::GraphiQLSource;
use async_graphql::{dynamic::*, Value};
use async_graphql_axum::GraphQL;
use axum::{
    response::{self, IntoResponse},
    routing::get,
    Router, Server,
};

async fn graphiql() -> impl IntoResponse {
    response::Html(GraphiQLSource::build().endpoint("/").finish())
}

#[tokio::main]
async fn main() {
    let query = Object::new("Query").field(Field::new(
        "value",
        TypeRef::named_nn(TypeRef::STRING),
        |_ctx| FieldFuture::new(async move { Ok(Some(Value::from(100))) }),
    ));

    let schema = Schema::build(query.type_name(), None, None)
        .register(query)
        .finish()
        .unwrap();
    let app = Router::new().route("/", get(graphiql).post_service(GraphQL::new(schema)));

    println!("GraphiQL IDE: http://localhost:8001");

    Server::bind(&"127.0.0.1:8001".parse().unwrap())
        .serve(app.into_make_service())
        .await
        .unwrap();
}

to reproduce copy the above code into a new rust project run cargo r then go to http://localhost:8001, enter

{
  value
}

as the query and run it

@RaphaelDarley RaphaelDarley added the question Further information is requested label Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant