Skip to content

Expurple/async-graphql-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

async_graphql_test

A test framework for async_graphql API servers in Rust.

Currently, it's published "as is" and barely documented.

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 and its dependencies (you already depend on those), and 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

# 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:

input UserForm {
  name: String!
}

type User {
  name: String!
  deletedAt: String
}

type Query {
  users: [User!]!
}

type Mutation {
  createUser(form: UserForm!): User!
}

License

Licensed under either of Apache License, Version 2.0 or MIT license 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.

About

A test framework for Rust GraphQL servers

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Contributors

Languages