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

Better documentation #1453

Open
ollyde opened this issue Dec 30, 2023 · 3 comments
Open

Better documentation #1453

ollyde opened this issue Dec 30, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@ollyde
Copy link

ollyde commented Dec 30, 2023

When I go to https://async-graphql.github.io/async-graphql/en/quickstart.html

I don't get a simple full example of a working server.

Instead I have to go though and try to find pages of docs in the example Github, which also isn't clear.

@ollyde ollyde added the enhancement New feature or request label Dec 30, 2023
@ollyde
Copy link
Author

ollyde commented Dec 30, 2023

For example, here is a basic full setup

main.rs


use actix_web::{guard, web, App, HttpResponse, HttpServer, Result};
use async_graphql::{http::GraphiQLSource, EmptyMutation, EmptySubscription, Schema};
use async_graphql_actix_web::GraphQL;

mod features;

use features::test::test_schema::TestSchema;

async fn index_graphiql() -> Result<HttpResponse> {
    Ok(HttpResponse::Ok()
        .content_type("text/html; charset=utf-8")
        .body(GraphiQLSource::build().endpoint("/").finish()))
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
    println!("GraphiQL IDE: http://localhost:8000");

    HttpServer::new(move || {
        let schema = Schema::build(TestSchema, EmptyMutation, EmptySubscription).finish();

        App::new()
            .service(
                web::resource("/")
                    .guard(guard::Post())
                    .to(GraphQL::new(schema)),
            )
            .service(web::resource("/").guard(guard::Get()).to(index_graphiql))
    })
    .bind("127.0.0.1:8000")?
    .run()
    .await
}

test_schema.rs

use async_graphql::{Context, EmptyMutation, EmptySubscription, Object, Schema};

pub struct TestSchema;

#[Object]
impl TestSchema {
    async fn hello(&self, ctx: &Context<'_>) -> String {
        "Hello, world!".to_string()
    }
}

pub type TestSchemaService = Schema<TestSchema, EmptyMutation, EmptySubscription>;

@kingsleyh
Copy link

There is also no understandable documentation that explains to make a schema that is not just hardcoded values. Also there is no explanation of what the context is or how to use it.

@Miaxos
Copy link
Member

Miaxos commented Feb 4, 2024

What the context is: https://async-graphql.github.io/async-graphql/en/context.html
Some examples that should help you: https://github.com/async-graphql/examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants