Hypothesis strategies for GraphQL schemas and queries
Project description
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
...
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
hypothesis-graphql-0.6.1.tar.gz
(12.0 kB
view hashes)
Built Distribution
Close
Hashes for hypothesis_graphql-0.6.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 343f7b59e2e981ac62de3e05f7554885cbfbd08288d41cd8cb5f65b8b8c3d33f |
|
MD5 | 1096369284eef6360f783895eb7aeae6 |
|
BLAKE2b-256 | 854d4b479d58911291be561bdaee19fc917d414d2773c265f506cb1a1cd7cdeb |