Hypothesis strategies for GraphQL schemas, queries and data.
NOTE This package is experimental, some features are not supported yet.
Usage
There are a few strategies for different use cases.
Schema generation - hypothesis_graphql.strategies.schemas()
Query - hypothesis_graphql.strategies.queries(schema).
Mutation - hypothesis_graphql.strategies.mutations(schema).
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]
}
type Mutation {
addBook(title: String!, author: String!): Book!
addAuthor(name: String!): 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.queries(SCHEMA))
def test_query(query):
...
# This query might be generated:
#
# query {
# getBooks {
# title
# }
# }
@given(mutation=gql_st.mutations(SCHEMA))
def test_mutation(mutation):
...
# This mutation might be generated:
#
# mutation {
# addBook(title: "H4Z\u7869", author: "\u00d2"){
# title
# }
# }
To restrict the set of fields in generated operations use the fields argument:
...
@given(query=gql_st.queries(SCHEMA, fields=["getAuthors"]))
def test_query(query):
# Only `getAuthors` will be generated
...
Release files for hypothesis-graphql 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| hypothesis-graphql-0.6.0.tar.gz | 11.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hypothesis_graphql-0.6.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.7 kB
Release files / hypothesis-graphql-0.6.0.tar.gz
| Download URL | hypothesis-graphql-0.6.0.tar.gz |
|---|---|
| Size | 11.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0faba624362bc173a3b7f77fc70fbcddb182e7a1f33c8a115950eb906a71ea62
|
|
BLAKE2b-256 checksum How to use checksums |
68267e8ddf44b3defd2150c6728a267e64543831668ce6a59428c8fe33dc831d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.12
|
Release files / hypothesis_graphql-0.6.0-py3-none-any.whl
| Download URL | hypothesis_graphql-0.6.0-py3-none-any.whl |
|---|---|
| Size | 14.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9922512472351e3485fa2ce1b1697df99b8813ac7e33ddbfa03e1b839bde3017
|
|
BLAKE2b-256 checksum How to use checksums |
24130afb9e273dbbcf8c83d1801a6fe6830d57232d33676ef2d964e7e0fae04a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.12
|