# async_graphql_test
A test framework for
[`async_graphql`](https://github.com/async-graphql/async-graphql) API servers in
Rust.
## Features
1. Widely-supported, plain-text format:
- Test cases as plain `.graphql` files.
- Assertions as GraphQL directives.
- Great IDE support. Interactive tweaking/debugging in GraphQL Playground,
etc.
- No rebuilds after editing your test cases!
2. Flexible, performant and lightweight:
- Async runtime-agnostic. The crate is just "plumbing", "pure", in-memory
logic.
- No HTTP/TLS stack required. Can read GraphQL inputs directly from memory.
- In fact, we only depend on
[`async_graphql`](https://github.com/async-graphql/async-graphql) and its
dependencies (you already depend on those), and
[`itertools`](https://github.com/rust-itertools/itertools).
- The crate is just a few functions. You can add arbitrary setup/teardown
around those.
- Integrate a snapshot testing library and snapshot the output.
## Example test case
```graphql
# Queries and mutations are executed from top to bottom.
#
# Use @directives to assert the relevant outputs directly,
# or integrate a snapshot testing library and snapshot the full server output.
# 1.
query initialUsers {
users @shouldHaveLength(n: 0) {
name
}
}
# 2.
mutation createUser {
createUser(form: {name: "John Doe"}) {
name @shouldBeEqual(to: "John Doe")
deletedAt @shouldBeNull
}
}
# 3.
query doubleCheckPersistenceUsingASeparateQuery {
users @shouldHaveLength(n: 1) {
name @shouldBeEqual(to: "John Doe")
deletedAt @shouldBeNull
}
}
```
Assuming the following schema:
```graphql
input UserForm {
name: String!
}
type User {
name: String!
deletedAt: String
}
type Query {
users: [User!]!
}
type Mutation {
createUser(form: UserForm!): User!
}
```
## Executable examples
See [`example-tests/`](./example-tests/).
## License
Licensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or
[MIT license](LICENSE-MIT) at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this crate by you, as defined in the Apache-2.0 license, shall
be dual licensed as above, without any additional terms or conditions.