Skip to content

Commit e5f5efc

Browse files
committed
misc: update README.md
1 parent 87a4279 commit e5f5efc

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed

README.md

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,78 @@ _Tested at Rust version: `rustc 1.53.0 (53cb7b09b 2021-06-17)`_
3939

4040
## Examples
4141

42-
Incoming.
42+
### Warp
43+
44+
A litle example to how to use it.
45+
If there is something unclear, please write an issue on the repo.
46+
Some examples are going to be written soon.
47+
48+
```rust
49+
use async_graphql_extension_apollo_tracing::{ApolloTracing, ApolloTracingDataExt, HTTPMethod, register::register};
50+
51+
async fn main() -> anyhow::Result<()> {
52+
...
53+
54+
let schema = Schema::build(Query::default(), Mutation::default(), EmptySubscription)
55+
.data(some_data_needed_for_you)
56+
.extension(ApolloTracing::new(
57+
"authorization_token".into(),
58+
"https://yourdomain.ltd".into(),
59+
"your_graph@variant".into(),
60+
"v1.0.0".into(),
61+
10,
62+
))
63+
.finish();
64+
65+
register("authorization_token", &schema, "my-allocation-id", "variant", "1.0.0", "staging").await?;
66+
67+
...
68+
69+
let client_name = warp::header::optional("apollographql-client-name");
70+
let client_version = warp::header::optional("apollographql-client-version");
71+
let env = my_env_filter();
72+
73+
let graphql_post = warp::post()
74+
.and(warp::path("graphql"))
75+
.and(async_graphql_warp::graphql(schema))
76+
.and(env)
77+
.and(client_name)
78+
.and(client_version)
79+
.and_then(
80+
|(schema, request): (
81+
Schema<Query, Mutation, EmptySubscription>,
82+
async_graphql::Request,
83+
),
84+
env: Environment,
85+
client_name: Option<String>,
86+
client_version: Option<String>| async move {
87+
let userid: Option<String> = env.userid().map(|x| x.to_string());
88+
89+
Ok::<_, std::convert::Infallible>(async_graphql_warp::Response::from(
90+
schema
91+
.execute(
92+
request.data(ApolloTracingDataExt {
93+
userid,
94+
path: Some("/graphql".to_string()),
95+
host: Some("https://yourdomain.ltd".to_string()),
96+
method: Some(HTTPMethod::POST),
97+
secure: Some(true),
98+
protocol: Some("HTTP/1.1".to_string()),
99+
status_code: Some(200),
100+
client_name,
101+
client_version,
102+
})
103+
.data(env),
104+
)
105+
.await,
106+
))
107+
},
108+
);
109+
110+
111+
112+
}
113+
```
43114

44115
## Incoming
45116

0 commit comments

Comments
 (0)