2019-12-07 18:59:35 +01:00
|
|
|
# Juniper
|
2018-04-13 03:18:42 +02:00
|
|
|
|
2020-05-19 07:23:28 +02:00
|
|
|
[Juniper](https://github.com/graphql-rust/juniper) integration for Actix web.
|
|
|
|
If you want more advanced example, see also the [juniper-advanced example].
|
|
|
|
|
2021-03-25 21:13:01 +01:00
|
|
|
[juniper-advanced example]: https://github.com/actix/examples/tree/master/graphql/juniper-advanced
|
2019-12-07 18:59:35 +01:00
|
|
|
|
|
|
|
## Usage
|
2018-04-13 03:18:42 +02:00
|
|
|
|
|
|
|
### server
|
|
|
|
|
|
|
|
```bash
|
2021-10-06 23:28:53 +02:00
|
|
|
cd graphql/juniper
|
2018-04-13 03:18:42 +02:00
|
|
|
cargo run (or ``cargo watch -x run``)
|
|
|
|
# Started http server: 127.0.0.1:8080
|
|
|
|
```
|
|
|
|
|
|
|
|
### web client
|
|
|
|
|
|
|
|
[http://127.0.0.1:8080/graphiql](http://127.0.0.1:8080/graphiql)
|
2019-12-07 18:59:35 +01:00
|
|
|
|
|
|
|
_Query example:_
|
2021-04-26 13:32:32 +02:00
|
|
|
|
2019-12-07 18:59:35 +01:00
|
|
|
```graphql
|
|
|
|
{
|
|
|
|
human(id: "1234") {
|
|
|
|
name
|
|
|
|
appearsIn
|
|
|
|
homePlanet
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
2021-04-26 13:32:32 +02:00
|
|
|
|
2019-12-07 18:59:35 +01:00
|
|
|
_Result:_
|
2021-04-26 13:32:32 +02:00
|
|
|
|
2019-12-07 18:59:35 +01:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"data": {
|
|
|
|
"human": {
|
|
|
|
"name": "Luke",
|
|
|
|
"appearsIn": [
|
|
|
|
"NEW_HOPE"
|
|
|
|
],
|
|
|
|
"homePlanet": "Mars"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
_Mutation example:_
|
|
|
|
|
|
|
|
```graphql
|
|
|
|
mutation {
|
|
|
|
createHuman(newHuman: {name: "Fresh Kid Ice", appearsIn: EMPIRE, homePlanet: "earth"}) {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
appearsIn
|
|
|
|
homePlanet
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
_Result:_
|
2021-04-26 13:32:32 +02:00
|
|
|
|
2019-12-07 18:59:35 +01:00
|
|
|
```json
|
|
|
|
{
|
|
|
|
"data": {
|
|
|
|
"createHuman": {
|
|
|
|
"id": "1234",
|
|
|
|
"name": "Fresh Kid Ice",
|
|
|
|
"appearsIn": [
|
|
|
|
"EMPIRE"
|
|
|
|
],
|
|
|
|
"homePlanet": "earth"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|