2022-02-17 21:29:55 +00:00
# GraphQL using Juniper
2018-04-13 09:18:42 +08:00
2022-03-06 00:43:10 +00:00
[Juniper ](https://github.com/graphql-rust/juniper ) integration for Actix Web. If you want more advanced example, see also the [juniper-advanced example].
2020-05-19 14:23:28 +09:00
2021-03-25 13:13:01 -07: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 09:18:42 +08:00
2022-02-17 20:37:51 +00:00
### Server
2018-04-13 09:18:42 +08:00
2022-02-17 20:37:51 +00:00
```sh
2021-10-06 17:28:53 -04:00
cd graphql/juniper
2022-02-17 20:37:51 +00:00
cargo run
2018-04-13 09:18:42 +08:00
```
2022-02-17 20:37:51 +00:00
### Web Client
2018-04-13 09:18:42 +08:00
2022-02-17 20:37:51 +00:00
Go to < http: / / localhost:8080 / graphiql > in your browser.
2019-12-07 18:59:35 +01:00
_Query example:_
2021-04-26 20:32:32 +09:00
2019-12-07 18:59:35 +01:00
```graphql
{
human(id: "1234") {
name
appearsIn
homePlanet
}
}
```
2021-04-26 20:32:32 +09:00
2019-12-07 18:59:35 +01:00
_Result:_
2021-04-26 20:32:32 +09:00
2019-12-07 18:59:35 +01:00
```json
{
"data": {
"human": {
"name": "Luke",
2022-03-06 00:43:10 +00:00
"appearsIn": ["NEW_HOPE"],
2019-12-07 18:59:35 +01:00
"homePlanet": "Mars"
}
}
}
```
_Mutation example:_
```graphql
mutation {
2024-08-07 02:04:57 +01:00
createHuman(newHuman: { name: "Fresh Kid Ice", appearsIn: EMPIRE, homePlanet: "earth" }) {
2019-12-07 18:59:35 +01:00
id
name
appearsIn
homePlanet
}
}
```
_Result:_
2021-04-26 20:32:32 +09:00
2019-12-07 18:59:35 +01:00
```json
{
"data": {
"createHuman": {
"id": "1234",
"name": "Fresh Kid Ice",
2022-03-06 00:43:10 +00:00
"appearsIn": ["EMPIRE"],
2019-12-07 18:59:35 +01:00
"homePlanet": "earth"
}
}
}
```