Hypothesis strategies for GraphQL schemas and queries
Project description
Hypothesis strategies for GraphQL schemas, queries and data.
NOTE This package is experimental, many things don’t work yet and documented in a way they are planned to be used.
Usage
There are four strategies for different use cases.
Schema generation - hypothesis_graphql.strategies.schema()
Query - hypothesis_graphql.strategies.query(schema).
Response for a query - hypothesis_graphql.strategies.response(schema, query)
Data for a type - hypothesis_graphql.strategies.data(schema, type_name)
At the moment only schema & query are working with some limitations.
Lets take this schema as an example:
type Book {
title: String
author: Author
}
type Author {
name: String
books: [Book]
}
type Query {
getBooks: [Book]
getAuthors: [Author]
}
Then strategies might be used in this way:
from hypothesis import given
from hypothesis_graphql import strategies as gql_st
SCHEMA = """...""" # the one above
@given(query=gql_st.query(schema))
def test_query(query):
...
# This query might be generated:
#
# query {
# getBooks {
# title
# }
# }
@given(response=gql_st.response(schema, query))
def test_response(response):
...
# Example response with a query from the example above:
#
# {
# "data": {
# "getBooks": [
# {"title": "War and Peace"}
# ]
# }
# }
@given(data=gql_st.data(schema, "Book"))
def test_data(data):
...
# Example data:
#
# {
# "title": "War and Peace"
# "author": {"name": "Leo Tolstoy"}
# }
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for hypothesis_graphql-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9cda6cd36d32816f858d4addeb363819726ef3d3c8375f12d3fcbd5690bab4f0 |
|
MD5 | b3b2cd8e0f67be9db5fdfd3692084c03 |
|
BLAKE2b-256 | 6804467317062df0ab827ae1d23beca5a5e20c015f207ec7fafc1775327ff163 |